您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Automatically toggle hidden built-in dark mode on zhihu.com
// ==UserScript== // @name Zhihu Auto Dark Mode // @namespace http://tampermonkey.net/ // @version 0.4 // @description Automatically toggle hidden built-in dark mode on zhihu.com // @author Nathaniel Wu // @include *.zhihu.com/* // @exclude *link.zhihu.com/* // @exclude *www.zhihu.com/question/*/log // @exclude *www.zhihu.com/people/*/logs // @license Apache-2.0 // @supportURL https://gist.github.com/Nathaniel-Wu/b2e6490f5ac7c35dc0cd902fda851b36 // @grant none // ==/UserScript== (function () { 'use strict'; const setDarkMode = on => { let alreadyOn = document.querySelector('html').getAttribute('data-theme') == 'dark'; if ((alreadyOn && (!on)) || ((!alreadyOn) && on)) { let keyword, keyword_replacement; if (on) { keyword = 'theme=light'; keyword_replacement = 'theme=dark'; } else { keyword = 'theme=dark'; keyword_replacement = 'theme=light'; } if (window.location.href.match(/theme=(dark|light)/)) window.location.href = window.location.href.replace(keyword, keyword_replacement); else { if (window.location.href.match(/\?[^=]+=/)) window.location.href = window.location.href + `&${keyword_replacement}`; else window.location.href = window.location.href + `?${keyword_replacement}`; } } } const in_iframe = () => { try { return window.self !== window.top; } catch (e) { return true; } } if (!in_iframe()) { if (window.matchMedia) {// if the browser/os supports system-level color scheme setDarkMode(window.matchMedia('(prefers-color-scheme: dark)').matches); window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', e => setDarkMode(e.matches)); } else {// otherwise use local time to decide let hour = (new Date()).getHours(); setDarkMode(hour > 18 || hour < 8); } } })();
QingJ © 2025
镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址