Custom Change Color Script

Заменяет указанные цвета на других доменах

Από την 26/11/2024. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name            Custom Change Color Script
// @name:ru         Скрипт для замены указанного цвета на страницы
// @namespace       http://tampermonkey.net/
// @version         1.1
// @description:en  Change specific colors to another on selected domains
// @description:ru  Заменяет указанные цвета на других доменах
// @author          Shaman_Lesnoy
// @match           *://*/*
// @grant           none
// @license         GPL-3.0
// @description Заменяет указанные цвета на других доменах
// ==/UserScript==

const SOURCE_COLOR = '#5cdd8b'; // целевой hex цвет
const TARGET_COLOR = '#93fab9'; // новый hex цвет
const ALLOWED_DOMAINS = ['example.com', 'anotherdomain.com']; // Список доменов

(function() {
    'use strict';

    const currentDomain = window.location.hostname;

    if (!ALLOWED_DOMAINS.some(domain => currentDomain.includes(domain))) {
        return;
    }

    function hexToRgb(hex) {
        const bigint = parseInt(hex.slice(1), 16);
        const r = (bigint >> 16) & 255;
        const g = (bigint >> 8) & 255;
        const b = bigint & 255;
        return `rgb(${r}, ${g}, ${b})`;
    }

    const sourceRgb = hexToRgb(SOURCE_COLOR);
    const targetColor = TARGET_COLOR;

    function updateColors() {
        document.querySelectorAll('*').forEach(el => {
            const styles = getComputedStyle(el);
            if (styles.color === sourceRgb) {
                el.style.setProperty('color', targetColor, 'important');
            }
            if (styles.backgroundColor === sourceRgb) {
                el.style.setProperty('background-color', targetColor, 'important');
            }
            if (styles.borderColor === sourceRgb) {
                el.style.setProperty('border-color', targetColor, 'important');
            }
        });
    }

    function processShadowRoots(node) {
        if (node.shadowRoot) {
            updateColorsInShadow(node.shadowRoot);
        }
        node.childNodes.forEach(child => processShadowRoots(child));
    }

    function updateColorsInShadow(shadowRoot) {
        shadowRoot.querySelectorAll('*').forEach(el => {
            const styles = getComputedStyle(el);
            if (styles.color === sourceRgb) {
                el.style.setProperty('color', targetColor, 'important');
            }
            if (styles.backgroundColor === sourceRgb) {
                el.style.setProperty('background-color', targetColor, 'important');
            }
            if (styles.borderColor === sourceRgb) {
                el.style.setProperty('border-color', targetColor, 'important');
            }
        });
    }

    const observer = new MutationObserver(() => {
        updateColors();
        processShadowRoots(document.body);
    });

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

    updateColors();
    processShadowRoots(document.body);
})();