ZhihuThemeSync

Keeps Zhihu’s theme in sync with your OS theme.

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

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

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

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.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         ZhihuThemeSync
// @name:zh-CN 知乎自动深色模式
// @name:zh-TW 知乎自動暗色模式
// @namespace    http://tampermonkey.net/
// @version      2025-10-14 .3
// @description  Keeps Zhihu’s theme in sync with your OS theme.
// @description:zh-CN 让知乎的主题与系统主题保持同步。
// @description:zh-TW 讓知乎的主題與系統主題保持同步。
// @author       Ethan Dong
// @match        https://*.zhihu.com/*
// @icon         https://www.google.com/s2/favicons?sz=256&domain=https://www.zhihu.com/
// @grant        none
// @run-at       document-start
// @license MIT
// ==/UserScript==

(function() {

    const themeMedia = window.matchMedia('(prefers-color-scheme: dark)');
    function updateThemeStatus(e){
        console.log("Triggered")
        let url = new URL(window.location.href);
        let params = url.searchParams;
        let sysTheme = "";
        let CurrentPageTheme = "";

        if (params.has("theme")){
            CurrentPageTheme = params.get("theme")
        }else{
            sysTheme = null
        }

        if (e.matches){
            sysTheme = "dark"
            params.set("theme","dark")

        }else{
            sysTheme = "light"
            params.set("theme","light")

        }

        if (CurrentPageTheme = null || sysTheme != CurrentPageTheme){
            window.location.href = url.toString();
            console.log("reloaded")
        }

    }
    updateThemeStatus(themeMedia);
    themeMedia.addEventListener('change', updateThemeStatus);


}
)();