V2EX Auto Dark Mode

Turn on/off dark mode automatically in v2ex.com based on the color scheme of OS.

Verze ze dne 01. 04. 2021. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name                 V2EX Auto Dark Mode
// @namespace            http://tampermonkey.net/
// @version              0.2
// @description          Turn on/off dark mode automatically in v2ex.com based on the color scheme of OS.
// @description:ZH-CN    根据系统配色自动开启/关闭 v2ex.com 的深色模式
// @author               Jiachen Chen
// @match                *://*.v2ex.com/*
// @match                *://v2ex.com/*
// @icon                 https://www.google.com/s2/favicons?domain=v2ex.com
// @grant                none
// ==/UserScript==

(function() {
    'use strict';

    const toggleLink = document.querySelector('.light-toggle').getAttribute('href');

    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
        if (SITE_NIGHT) {
            window.location.replace(toggleLink);
        }
    }

    window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', e => {
        if (SITE_NIGHT) {
            window.location.replace(toggleLink);
        }
    });

    if (window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
        if (SITE_NIGHT === 0) {
            window.location.replace(toggleLink);
        }
    }

    window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => {
        if (SITE_NIGHT === 0) {
            window.location.replace(toggleLink);
        }
    });
})();