Hordes.io - A draft of beer

Just a normal beer

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Hordes.io - A draft of beer
// @namespace    http://tampermonkey.net/
// @version      1.5
// @description  Just a normal beer
// @author       WindyHills
// @match        https://hordes.io/play
// @grant        none
// @license      Proprietary - Do not redistribute without permission! or something else. you understand.
// ==/UserScript==

(function () {
    'use strict';

    const config = {
        performance: false // Change to "true" to performance mode
    };

    const srcMappings = {
        "/data/items/misc/misc4_q0.avif?v=8822612": "https://i.ibb.co/bQJDc9d/beer-barley.png",
        "/data/items/misc/misc4_grey.avif?v=8822612": "https://i.ibb.co/0yR7r21/beer-barley-grey.png"
    };

    const textMappings = {
        "Large HP Potion": "Beer",
        "A potion flask containing a red liquid, healing you as you drink it.":
            "An artisan beer with a taste that lingers on your palate! Enjoy it between your adventures to relax and unwind, but be careful—too much might leave you a bit dizzy!",
        "1000 HP recovered": "+2 Nausea"
    };

    function updateImages() {
        for (const [original, replacement] of Object.entries(srcMappings)) {
            const imgs = document.querySelectorAll(`img[src="${original}"]`);
            imgs.forEach(img => {
                if (img.src !== replacement) img.src = replacement;
            });
        }
    }

    function replaceText() {
        const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT, null, false);
        let node;
        while ((node = walker.nextNode())) {
            let replaced = node.nodeValue;
            for (const [original, replacement] of Object.entries(textMappings)) {
                if (replaced.includes(original)) {
                    replaced = replaced.replace(original, replacement);
                }
            }
            if (replaced !== node.nodeValue) {
                node.nodeValue = replaced;
            }
        }
    }

    function main() {
        updateImages();
        replaceText();
    }

    let observer;

    if (config.performance) {
        let debounceTimer;
        const debouncedMain = () => {
            clearTimeout(debounceTimer);
            debounceTimer = setTimeout(main, 30);
        };

        observer = new MutationObserver(debouncedMain);
    } else {
        observer = new MutationObserver(main);
    }

    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();