XP Involker

XP Free

目前為 2024-10-11 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         XP  Involker
// @namespace    https://greasyfork.org/en/scripts/507701-xp-involker
// @version      1.60
// @description  XP Free
// @author       MrBonkeiro
// @match        https://bonk.io/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=bonk.io
// @run-at       document-idle
// @grant        none
// ==/UserScript==

function getBonk() {
    const iframe = document.getElementById('maingameframe');
    if (!iframe) {
        console.error('[MrMenu] Iframe not found');
        return null;
    }

    const iframeDoc = iframe.contentDocument || iframe.contentWindow.document;
    if (!iframeDoc) {
        console.error('[MrMenu] Iframe document not found');
        return null;
    }

    return iframeDoc;
}

function addHTML(htmlString, selector, beforeSelector = null)
{
    const bonkDoc = getBonk();
    const targetElement = bonkDoc.querySelector(selector);
    if (!targetElement) { return; }

    const parser = new DOMParser();
    const doc = parser.parseFromString(htmlString, 'text/html');
    const newElements = Array.from(doc.body.childNodes);

    if (beforeSelector) {
        const beforeElement = bonkDoc.querySelector(beforeSelector);
        if (!beforeElement) { return; }
        newElements.forEach(node => {
            beforeElement.parentNode.insertBefore(node, beforeElement);
        });
    } else {
        newElements.forEach(node => {
            targetElement.appendChild(node);
        });
    }
}
function isRoom() {
    const bonkDoc = getBonk();
    if (!bonkDoc) return false;

    const element = bonkDoc.getElementById('gamerenderer');
    if (element) {
        return window.getComputedStyle(element).visibility === 'inherit';
    }

    return false;
}

function Init() {
  
    addHTML(`<div style="background-color: #1f1f1f; display: flex; position: absolute; top: 50%; left: 50%; width: 85%; height: 85%; transform: translate(-50%, -50%);"> 
        <img src="https://bonk.io/graphics/flags/br.png" style="width: 18px; height: 16px;"></img>
        <label>Baixe nova versão do XP Involker in MrMenu e remova está versão velha do XP Involker</label>

        <img src="https://bonk.io/graphics/flags/us.png" style="width: 18px; height: 16px;"></img>
        <label>Download new version XP Involker no MrMenu and remove XP Involker old</label>
        
        <a href="https://greasyfork.org/en/scripts/504571-mrmenu"></a>
    
    </div>`, '#bonkiocontainer');
    let getWS;
    let timer = null;
    let deletePressed = false;

    function XP()
    {
         if (isRoom && getWS != null) { getWS.send('42[38]');}

    }

    function handleDeleteKey(event) {
      if (event.key === "Delete"|| event.key === "L" || event.key === "l") {
        if (!deletePressed) {
          deletePressed = true;
          timer = setInterval(XP, 6000);
          getBonk().getElementById('xpbarfill').style.backgroundColor = 'lightgreen';
        } else {
          clearInterval(timer);
          deletePressed = false;
          getBonk().getElementById('xpbarfill').style.backgroundColor = '#473aaf';

        }
      }
    }

    getBonk().addEventListener("keydown", handleDeleteKey);

    const originalSend = getBonk().defaultView.WebSocket.prototype.send;
    getBonk().defaultView.WebSocket.prototype.send = function (...args) {
        if (this.url.includes('socket.io')) {
            getWS = this;

            const originalOnMessage = this.onmessage;
            this.onmessage = function (msg) {
                return originalOnMessage.call(this, msg);
            };

            const originalOnClose = this.onclose;
            this.onclose = function () {
                getWS = null;
                return originalOnClose.call(this);
            };
        }

        return originalSend.apply(this, args);
    };
}

function ScriptInjector(f) {
    if (window.location === window.parent.location) {
        if (document.readyState === 'complete') {
            setTimeout(f, 1200);
        } else {
            document.addEventListener('readystatechange', function () {
                setTimeout(f, 3500);
            });
        }
    }
}


ScriptInjector(Init);