subaranshi / Kostumy Stayi

// ==UserScript==
// @name         Kostumy Stayi
// @namespace    http://tampermonkey.net/
// @version      2025-05-02
// @description  try to take over the world!
// @author       Чудо
// @license MIT
// @match        https://catwar.net/cw3/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=catwar.net
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    console.log("✅ Userscript завантажився");

    // 🔁 Додавай тут свої заміни. match — частина URL, replaceWith — нове зображення
    const replacements = [
        {
            match: "composited/4e9ca9ce415113b1.png", //чудо
            replaceWith: "https://i.ibb.co/pvT0jNgQ/image.png"
        },
        {
            match: "composited/fc145d9b41f7f47c.png", //луч
            replaceWith: "https://i.ibb.co/ccYvs6hL/image.png"
        },
         {
            match: "composited/b8a7e081bc288299.png", //ксю
            replaceWith: "https://i.ibb.co/8nLffHtt/image.png"
        },
         {
            match: "composited/4ec170b4945b25ba.*png", //горе
            replaceWith: "-"
        },
        {
            match: "composited/90e3a0aa0e0cc5a5.png", //шептя
            replaceWith: "https://i.ibb.co/mFM8MNL4/image.png"
        },
        {
            match: "composited/65162b37e8f843cd.png", //смол
            replaceWith: "https://i.ibb.co/qK40vY4/17-20250429194657.png"
        }
        // Додай ще сюди ⬆️
    ];

    function replaceImgAndBackground(node) {
        // <img> елементи
        if (node.tagName === 'IMG') {
            for (const { match, replaceWith } of replacements) {
                if (node.src.includes(match)) {
                    console.log(`🔁 Заміна IMG: ${node.src} → ${replaceWith}`);
                    node.src = replaceWith;
                    break;
                }
            }
        }

        // елементи з CSS background-image
        const computedStyle = getComputedStyle(node);
        const bgImage = computedStyle.backgroundImage;
        for (const { match, replaceWith } of replacements) {
            if (bgImage.includes(match)) {
                console.log(`🔁 Заміна BG: ${bgImage} → ${replaceWith}`);
                node.style.backgroundImage = `url("${replaceWith}")`;
                break;
            }
        }

        // перевірити всі дочірні елементи
        node.querySelectorAll?.('*').forEach(child => replaceImgAndBackground(child));
    }

    // Запустити одразу
    replaceImgAndBackground(document.body);

    // Стежити за новими елементами
    const observer = new MutationObserver(mutations => {
        for (const mutation of mutations) {
            mutation.addedNodes.forEach(node => {
                if (node.nodeType === 1) {
                    replaceImgAndBackground(node);
                }
            });
        }
    });

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