Greasy Fork is available in English.
知乎开启黑夜模式
// ==UserScript==
// @name 知乎黑夜模式
// @namespace https://github.com/cyh-2003
// @version 1.0.0
// @description 知乎开启黑夜模式
// @author 骑着老王闯天下
// @match https://*.zhihu.com/*
// @icon https://www.zhihu.com/favicon.ico
// @grant none
// @run-at document-start
// @license The Unlicense
// ==/UserScript==
(function () {
'use strict'
// 检查当前URL是否已经包含theme参数
const url = new URL(window.location.href)
const hasThemeParam = url.searchParams.has('theme')
const currentTheme = url.searchParams.get('theme')
// 如果不是黑夜模式,则添加参数
if (!hasThemeParam || currentTheme !== 'dark') {
url.searchParams.set('theme', 'dark')
// 使用replace而不是直接赋值,避免产生浏览器历史记录
window.location.replace(url.toString())
}
})();