Hordes.io - A draft of beer

Just a normal beer

// ==UserScript==
// @name         Hordes.io - A draft of beer
// @namespace    http://tampermonkey.net/
// @version      1.4
// @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';

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

    // Text mappings
    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 to replace image sources
    function updateImages() {
        Object.entries(srcMappings).forEach(([original, replacement]) => {
            document.querySelectorAll(`img[src="${original}"]`).forEach(img => {
                img.src = replacement;
            });
        });
    }

    // Function to replace text content
    function replaceText() {
        document.body.querySelectorAll('*:not(script):not(style)').forEach(element => {
            element.childNodes.forEach(node => {
                if (node.nodeType === Node.TEXT_NODE) {
                    Object.entries(textMappings).forEach(([original, replacement]) => {
                        node.nodeValue = node.nodeValue.replace(original, replacement);
                    });
                }
            });
        });
    }

    function main() {
        updateImages();

        replaceText();
    }

    const observer = new MutationObserver(() => {
        main();
    });

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