知乎 - 强行开启夜间模式

根据网页源代码,很久以前,知乎网页版就已经有了夜间模式。设置项都有了。但官方迟迟不开放使用。等不下去了,先这样了。

目前为 2020-03-10 提交的版本。查看 最新版本

// ==UserScript==
// @name        知乎 - 强行开启夜间模式
// @description 根据网页源代码,很久以前,知乎网页版就已经有了夜间模式。设置项都有了。但官方迟迟不开放使用。等不下去了,先这样了。
// @namespace   RainSlide
// @author      RainSlide
// @icon        https://static.zhihu.com/static/favicon.ico
// @version     1.0
// @match       https://*.zhihu.com/*
// @grant       none
// @inject-into context
// @run-at      document-start
// ==/UserScript==

document.documentElement.setAttribute( "data-theme", "dark" );

document.addEventListener(
	"DOMContentLoaded", () => {
		const initialData =
			document.getElementById("js-initialData");
		if ( initialData ) {
			initialData.textContent =
				initialData.textContent.replace(
					'"theme":"light"', '"theme":"dark"'
				);
		}
	}
);

/*
const setDataTheme =
	() => document.documentElement.setAttribute( "data-theme", "dark" );

setDataTheme();

new MutationObserver(
	( mutationList, observer ) => {
		setDataTheme();
		observer.disconnect();
	}
).observe(
	document.documentElement, {
		attributes: true,
		attributeFilter: [ "data-theme" ]
	}
);
*/

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址