Greasy Fork

全局暗模式

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

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

// ==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.02.02.19:34
// @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.getValue
// @grant             GM.setValue
// @grant             GM_registerMenuCommand
// ==/UserScript==
(async () => {
(await GM.getValue("Blist") == undefined) ? GM.setValue("Blist", "") : await GM.getValue("Blist")
let Blist = (await GM.getValue("Blist")),
    runIt = Blist == "" || Blist.replaceAll(/\s/g,'').split(/\r\n|\r|\n|,/g).filter(w => window.location.hostname.indexOf(w) > -1).length == 0,
    Btgle = () => {let e = document.querySelector("#GDM_option"); (e.style.display == "none") ? e.style.display = "block" : (e.style.display = "none", GM.setValue('Blist', document.querySelector('#GDM_filter').value))}
document.querySelector("body").insertAdjacentHTML('beforeend', `
<div id="GDM_option" style="position: fixed; top: 26px; right: 28px; width: 375px; z-index: 2147483647; background-color: #FFF; border-radius: 8px; display: none; box-shadow: 0 0 0 1px #dadce0;">
    <div style="height:50px">
        <div style="display:inline-block; position:absolute; left: 0; text-align: center; width: 50px; height: 50px">
            <div style="position:absolute; top: 50%; left: 50%; transform:translate(-50%, -50%); font-size:25px; user-select: none;">🪐</div>
        </div>
        <div style="display:inline-block; position:absolute; left: 50px; width: 275px; height: 50px; color:#000; user-select: none;">
            <span style="position:absolute; top: 50%; transform: translateY(-50%); font-size:14px; font-weight: bold; font-family:Verdana!important">Exclude Filter</span>
        </div>
        <div style="display:inline-block; position:absolute; right: 0; text-align: center; width: 50px; height: 50px">
            <div style="position:absolute; top: 50%; left: 50%; transform:translate(-50%, -50%); cursor: pointer" id="GDM_save">
                <svg xmlns="https://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="#5f6368" style="height:24px">
                    <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"></path>
                </svg>
            </div>
        </div>
    </div>
    <div class="byu-textarea">
        <textarea spellcheck="false" id="GDM_filter" placeholder="example.com,\nlotemipsum.com"
        style="min-width: 100%; max-width: 100%; min-height: 237px; box-sizing: border-box; border: 0; border-top: 1px solid #dadce0;
        padding: 5px 8px; margin-left: 1px; outline-color: transparent; font-size:14px; font-family:Courier New!important" background-color:white!important; color: #4d5156!important>`+Blist+`</textarea>
    </div>
</div>`)
document.querySelector('#GDM_save').addEventListener('click', () => {Btgle()})

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 (runIt) {
    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("Filter Toggle", Btgle)
GM_registerMenuCommand("On/Off Toggle", togle)
})()