Gimkit Dark Mode

Dark mode

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Gimkit Dark Mode
// @namespace    http://tampermonkey.net/
// @version      1.0
// @license      MIT
// @description  Dark mode
// @author       generic
// @match        https://*.gimkit.com/*
// @grant        GM_addStyle
// ==/UserScript==

(function() {
    'use strict';

    // Function to change colors of non-text elements (excluding images)
    function changeColors() {
        const elements = document.querySelectorAll('*:not(img):not(svg):not(path):not(script):not(style):not([data-original-color])');

        elements.forEach(element => {
            const computedStyle = getComputedStyle(element);
            const backgroundColor = computedStyle.backgroundColor;
            const textColor = computedStyle.color;

            if (backgroundColor) {
                // Calculate luminance for background color
                const bgLuminance = calculateLuminance(backgroundColor);
                if (bgLuminance > calculateLuminance('rgb(195, 195, 195)')) {
                    element.style.backgroundColor = '#161616';
                    // Store the original background color to prevent repeated changes
                    element.setAttribute('data-original-color', backgroundColor);
                }
            }

            if (textColor) {
                // Change text color to white
                element.style.color = '#fcfcfc';
            }
        });
    }

    // Function to calculate luminance from RGB values
    function calculateLuminance(rgb) {
        const parts = rgb.match(/^rgb\((\d+),\s*(\d+),\s*(\d+)\)$/);
        if (parts) {
            const r = parseInt(parts[1]) / 255;
            const g = parseInt(parts[2]) / 255;
            const b = parseInt(parts[3]) / 255;
            return 0.2126 * r + 0.7152 * g + 0.0722 * b;
        }
        return 0;
    }

    // Function to periodically check and change colors
    function periodicallyCheckColors() {
        setInterval(changeColors, 1); // Check every 0.00001 seconds (10 milliseconds)
    }

    // Function to apply color change when navigating within the site
    function applyColorChangeOnNavigation() {
        const observer = new MutationObserver(changeColors);
        const config = { childList: true, subtree: true };

        observer.observe(document.body, config);
    }

    // Run the color-changing function when the page loads
    window.addEventListener('load', () => {
        changeColors();
        applyColorChangeOnNavigation();
        periodicallyCheckColors();
    });
})();