全局暗模式

它只会将明亮的网站变为黑暗。

当前为 2021-12-22 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name              Global Darkmode
// @name:ko           글로벌 다크모드
// @name:jp           グローバルダークモード
// @name:zh-TW        全局暗模式
// @name:zh-CN        全局暗模式

// @description       Turn only bright websites to dark.
// @description:ko    밝은 색의 웹 사이트들만 어둡게 만듭니다.
// @description:jp    明るいウェブサイトだけを暗くします。
// @description:zh-TW 它只會將明亮的網站變為黑暗。
// @description:zh-CN 它只会将明亮的网站变为黑暗。

// @namespace         https://ndaesik.tistory.com/
// @version           2021.12.22.19:32
// @author            ndaesik
// @icon              data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><text x="-19vh" y="84vh" font-size="100vh">🪐</text></svg>
// @include           *
// ==/UserScript==
const
bodyH = window.parent.document.body.offsetHeight,
elems = document.querySelectorAll("body > :not(script)"),
apply = () => {document.head.appendChild(drkMo)},
drkMo = document.createElement("style")
drkMo.innerText = `
:root {color-scheme:dark;color:#000}
html * {color-scheme:light!important;text-shadow:0 0 .1px}
html body {background:none!important}
html, html :is(i, img, image, embed, video, canvas, option, object, :fullscreen:not(iframe), iframe:not(:fullscreen)),
html body>* [style*="url("]:not([style*="cursor:"]):not([type="text"]) {filter:invert(1)hue-rotate(180deg)!important}
html body>* [style*="url("]:not([style*="cursor:"]) :not(#⁠),
html:not(#⁠) :is(canvas, option, object) :is(i, img, image, embed, video),
html:not(#⁠) video:fullscreen{filter:unset!important}`
function whiteChecker(m,m2=0) {
    function n(n) {return parseInt(getComputedStyle(document.querySelectorAll(m)[m2], null).getPropertyValue("background-color").match(/\d+/g)[n])};
    return (n(0)*0.299+n(1)*0.587+n(2)*0.114) > 186 || n(3) == 0 // return true when it's background is whitish
};
if ((self == top && bodyH != 0 || self != top) && (whiteChecker("html") && whiteChecker("body"))) apply();
if (bodyH == 0) {for (var a = 0, j = elems.length; a < j ; a++) {if (elems[a].scrollHeight > window.innerHeight && whiteChecker("body > :not(script)",a)) apply();}};