Greasy Fork

Greasy Fork is available in English.

dark mode

Auto Dark Mode

当前为 2024-05-07 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         dark mode
// @description  Auto Dark Mode
// @version      1.0
// @author       Anc
// @match        *://*/*
// @exclude 		*://*localhost*
// @exclude 		*://*127.0.0.1*
// @exclude 		*://*sspai.*
// @exclude 		*://*github.*
// @exclude 		*://*v2ex.com/*
// @exclude 		*://*appinn.*
// @exclude 		*://*twitter.*
// @exclude 		*://*192.168.*
// @exclude 		*://*gcores.*
// @exclude 		*://*ithome.com/*
// @exclude 		*://*reddit.com/*
// @exclude 		*://*mp.weixin.qq.com/*
// @exclude 		*://wifi.airchina.com/*
// @exclude 		*://rebang.today/*
// @exclude 		*://m.hupu.com/*
// @exclude 		*://m.douyin.com/*
// @exclude 		*://ddys.tv/*
// @exclude 		*://www.mvcat.com/*
// @exclude 		*://pan.quark.cn/*
// @exclude 		*://ddys.*
// @exclude 		*://*ecosia.org/*
// @exclude 		*://vr.akan.com.cn/h5/app/*
// @exclude 		*://*steamcommunity.com/*
// @exclude 		*://www.greenmangaming.com/*
// @exclude 		*://chat.openai.com/*
// @exclude 		*://learn.microsoft.com/*
// @exclude 		*://app.gamersky.com/*
// @exclude 		*://*.epicgames.com/*
// @exclude 		*://paipai.m.jd.com/*
// @exclude 		*://*bing.com/*
// @run-at		 document.start
// @grant        GM.addStyle
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @noframes
// @namespace http://greasyfork.icu/users/61607
// ==/UserScript==

(function() {
    'use strict';
    // Add meta tag
    let meta = document.createElement('meta');
    meta.name = "theme-color";
    meta.content = "#000";
    meta.media = "(prefers-color-scheme: dark)";
    document.head.append(meta);

    // Function to create a button
    function createButton() {
        var button = document.createElement('button');
        button.textContent = 'White';

        button.style.position = 'fixed';
        button.style.top = '10px';
        button.style.right = '10px';
        button.style.padding = '10px';
        button.style.backgroundColor = '#007bff';
        button.style.color = '#ffffff';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.style.zIndex = '999';

        document.body.appendChild(button);

        button.addEventListener('click', function() {
            var elements = document.getElementsByTagName('*');

            for (var i = 0; i < elements.length; i++) {
                elements[i].style.filter = 'unset';
            }
        });
    }


    // Function to add the current website's domain to the array and save it
    function addDomainToArray() {
        var domain = window.location.hostname;
        var trackedDomains = GM_getValue('trackedDomains', []);

        // Check if domain already exists in the array
        var index = trackedDomains.indexOf(domain);
        if ( index === -1) {
            trackedDomains.push(domain);
            GM_setValue('trackedDomains', trackedDomains);
            console.log('Domain ' + domain + ' added to tracking list.');
        } else {
            console.log('Domain ' + domain + ' is already in tracking list, remove it.');
            trackedDomains.splice(index, 1);
            GM_setValue('trackedDomains', trackedDomains);
            console.log("trackedDomains", trackedDomains);
        }
    }

    // Function to check if the current domain is in the array and alert if so
    function checkDomain() {
        var domain = window.location.hostname;
        var trackedDomains = GM_getValue('trackedDomains', []);
        console.log("trackedDomains", trackedDomains);

        if (trackedDomains.indexOf(domain) !== -1){
            console.log('You are visiting a tracked domain: ' + domain);

            // Add style
            GM.addStyle(`
                @media (prefers-color-scheme: dark) {
                :root {
                        filter: invert(1) hue-rotate(180deg);
                    }
	            figure,img,video,iframe,div[style*=image]{
                        filter: invert(1) hue-rotate(180deg);
                        opacity:1;
                    }

                figure img {
                        filter: unset;
                    }
                }
            `)

            if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
                createButton();
            }

        }
    }

    // Register a menu command to add the current domain to the tracking list
    GM_registerMenuCommand('Add/Reomove', addDomainToArray);

    // Check the domain when the page loads
    checkDomain();
})();