Wiki Game Cheat

Right-click any link on the page or press W to win!

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

You will need to install an extension such as Tampermonkey to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Wiki Game Cheat
// @namespace    http://tampermonkey.net/
// @version      2.7
// @description  Right-click any link on the page or press W to win!
// @license      MIT
// @match        https://www.thewikigame.com/*
// @icon         https://www.thewikigame.com/favicon.ico
// @grant        none
// ==/UserScript==

(function () {

    function triggerWinOnLink(link) {
        if (!link) return;
        const titleDiv = document.querySelector("div.text-2xl.text-center.font-bold.font-noto-serif");
        if (!titleDiv) return;
        const text = titleDiv.textContent.trim().replace(/ +/g, "_");
        link.href = "./" + text;
        const events = ["pointerdown", "mousedown", "mouseup", "click"];
        for (const type of events) {
            const evt = new MouseEvent(type, { bubbles: true, cancelable: true, view: window, button: 0 });
            link.dispatchEvent(evt);
        }
    }

    function simulateTitleClick() {
        const titleDiv = document.querySelector("div.text-2xl.text-center.font-bold.font-noto-serif");
        if (!titleDiv) return;
        const events = ["pointerdown", "mousedown", "mouseup", "click"];
        for (const type of events) {
            const evt = new MouseEvent(type, { bubbles: true, cancelable: true, view: window, button: 0 });
            titleDiv.dispatchEvent(evt);
        }
    }

    function doWin(doc) {
        simulateTitleClick();
        const link = doc.querySelector("a[rel='mw:WikiLink'][href^='./']");
        triggerWinOnLink(link);
    }

    function hookIframe() {
        const iframe = document.querySelector("iframe");
        if (!iframe) return;

        iframe.addEventListener("load", () => {
            const doc = iframe.contentDocument;
            if (!doc) return;

            doc.addEventListener("contextmenu", function(e) {
                const link = e.target.closest("a[rel='mw:WikiLink']");
                if (!link) return;
                e.preventDefault();
                e.stopPropagation();
                triggerWinOnLink(link);
            });

            doc.addEventListener("keydown", function(e) {
                if (e.key.toLowerCase() !== "w") return;
                doWin(doc);
            });
        });
    }

    window.addEventListener("keydown", function(e) {
        if (e.key.toLowerCase() !== "w") return;
        const iframe = document.querySelector("iframe");
        if (!iframe || !iframe.contentDocument) return;
        doWin(iframe.contentDocument);
    });

    const observer = new MutationObserver(hookIframe);
    observer.observe(document.body, { childList: true, subtree: true });
    hookIframe();

})();