Zhihu.com Dark Mode

Enable Zhihu.com Dark Mode

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==UserScript==
// @name                Zhihu.com Dark Mode
// @name:zh-CN          知乎黑暗模式
// @name:zh-TW          知乎黑暗模式
// @namespace           https://www.zhihu.com/
// @version             0.7
// @description         Enable Zhihu.com Dark Mode
// @description:zh-CN   开启知乎黑暗模式
// @description:zh-TW   开启知乎黑暗模式
// @author              老蛤
// @match               *://*.zhihu.com/*
// @license             MIT
// ==/UserScript==


(function() {
    'use strict';

    const ignoreList = [
        'link.zhihu.com',
        'video.zhihu.com',
        'www.zhihu.com/pub/book',
        'www.zhihu.com/tardis',
    ];

    const checkURL = (url) => {
        for (const u of ignoreList) {
            if (url.indexOf(u) !== -1) {
                return false
            }
        }
        return true;
    };

    if (checkURL(location.href) && document.querySelector('html').getAttribute('data-theme') !== 'dark') {
        const url = new URL(location.href);
        const params = new URLSearchParams(url.search);
        params.set('theme', 'dark');
        url.search = params.toLocaleString();
        location.href = url.href;
    }
})();