// ==UserScript== // @name 知乎黑夜模式 // @description 知乎开启黑夜模式 // @version 1.0.0 // @author girl-dream // @license The Unlicense // @namespace https://github.com/girl-dream // @match https://*.zhihu.com/* // @icon https://www.zhihu.com/favicon.ico // @run-at document-start // @early-start // ==/UserScript== (() => { 'use strict' const url = new URL(location.href) const hasThemeParam = url.searchParams.has('theme') const currentTheme = url.searchParams.get('theme') if (!hasThemeParam || currentTheme !== 'dark') { window.stop() url.searchParams.set('theme', 'dark') location.replace(url.toString()) } if (location.href.indexOf('link.zhihu.com') != -1) { const style = ` html { background-color: #0A0A0A; } .wrapper { background-color: #222; } * { color: #fff; } ` const styleSheet = new CSSStyleSheet() styleSheet.replaceSync(style) document.adoptedStyleSheets.push(styleSheet) document.onreadystatechange = () => { document.querySelector('img').src = 'https://static.zhihu.com/static/img/logo.png' } } })();