全局暗模式

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

目前为 2022-01-28 提交的版本。查看 最新版本

// ==UserScript==
// @name:ko           글로벌 다크모드
// @name              Global Darkmode
// @name:ru           Глобальный темный режим
// @name:jp           グローバルダークモード
// @name:zh-TW        全局暗模式
// @name:zh-CN        全局暗模式

// @description:ko    밝은 색의 웹 사이트들만 어둡게 만듭니다.
// @description       Turn only bright websites to dark.
// @description:ru    Делайте темными только яркие сайты.
// @description:jp    明るいウェブサイトだけを暗くします。
// @description:zh-TW 它只會將明亮的網站變為黑暗。
// @description:zh-CN 它只会将明亮的网站变为黑暗。

// @namespace         https://ndaesik.tistory.com/
// @version           2022.01.28.20:27
// @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           *

// @grant             GM_registerMenuCommand
// ==/UserScript==
let bdyH0 = window.parent.document.body.offsetHeight == 0,
    frame = self != top,
    elems = document.querySelectorAll("body > :not(script)"),
    apply = () => document.head.appendChild(drkMo),
    togle = () => (document.querySelector(".drkMo") == null) ? apply() : document.querySelector(".drkMo").remove(),
    drkMo = document.createElement("style"),
    check = (m,m2=0) => {
    let n = (n) => {return parseInt(getComputedStyle(document.querySelectorAll(m)[m2]).getPropertyValue("background-color").match(/\d+/g)[n])};
    return (n(0)*0.299+n(1)*0.587+n(2)*0.114) > 186 || n(3) == 0 }
drkMo.innerText = `
html {color-scheme:dark!important;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}`
drkMo.classList.add("drkMo")
if ((!frame && !bdyH0 || frame) && check("html") && check("body")) apply()
if (!frame && bdyH0) {for (let i = 0; i < elems.length ; i++) {if (elems[i].scrollHeight > window.innerHeight && check("body > :not(script)",i)) apply()}}
GM_registerMenuCommand("DarkMode Toggle", togle)

QingJ © 2025

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