Global Darkmode

Turn in bright websites to dark.

Ajankohdalta 25.10.2021. Katso uusin versio.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name       Global Darkmode
// @description Turn in bright websites to dark.

// @name:ko        글로벌 다크모드
// @description:ko  밝은 색의 웹 사이트들을 어둡게 만듭니다.

// @namespace   https://ndaesik.tistory.com/
// @version     2021.10.25.19:12
// @author      ndaesik
// @icon        data:image/webp;base64,iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAMAAAD04JH5AAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAJSUExURUdwTICAgICAgICAgAAAAAAAAICAgICAgICAgAAAAICAgICAgICAgICAgICAgICAgICAgICAgAAAAICAgICAgH9/f39/f4KCgoCAgICAgICAgICAgICAgH9/f////4CAgICAgICAgH9/fyEhIYKCgoCAgICAgH5+foCAgFhYWGNjY4SEhBkZGYGBgYGBgYGBgYCAgHBwcBwcHHd3d4CAgICAgFFRUYCAgBwcHICAgD4+PgAAAICAgC4uLl5eXgAAAICAgICAgEVFRX19fWhoaHt7e3FxcYCAgEBAQG1tbTMzM4GBgYCAgBoaGnZ2doGBgYCAgH19faSkpGBgYGZmZoCAgHZ2dhUVFXd3d4CAgEdHR2lpaTY2NkJCQoGBgW9vb29vb4GBgYCAgICAgICAgGlpaWpqaoCAgJOTk4CAgCgoKIKCgoCAgBsbGwAAAF1dXUZGRsHBwXV1dYGBgX9/f2h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KC0CFExRm/AEF0nRhPqS7lW48DOn2043gGsi2jK6ssiDZR3TnB0j2Jd2pmwi5HqNLDZDrLrq1GlI9Tde6INM+uncJEh2he9m5kOdjepDbDGl20YuOmZAlbNKL1EzIEqcn1ZshyVR6M24u5EjSo+x1kOI4vTLehQyL6N0XkGAnfWiYCN/Cx+hD3fsW/OqhL6smwac36U/wt/nw5Vn69iD8CN9Iv4zABPhwiv4ZqX54dgulmL5uD7yJhChH6PA3gxBhDV5Avh5KYyy414KzyNnhrHkO+VqilMlc8AbsrBzK8bJ/MFovJZsSS49/e/tWC9esXbr4+b21QV5xHqOtpxrRWKKmteNYU29tkPlOWygQoFb/odCH1CnzMgq1NVOjehR7khrNRrG2dmpTj1J2UxcTJUVOUw/jR5S2hHpMh50d1MF4C7YC1OA92FtYR+WSYTg4StXSs+DoJyr2Apw9HqdSf6Gc+wwqFEd5G6nOiTAEDISoSG4ehGwwqcShPgi6x6QCgT4I2xCidJmVcGGAssUOwpWNBqVaHoFLZ+KU6LMZcO1kN2WJHrDgxdEEpah5Bh5d30QJ2lvg3Q76FfwFvvzcSF9ug1+R3XPoWWMnJGgbbqYnW1ZAkqqvA3TLePQIZPqkOUoXotWTId0DIQpKDEGJyB1DCZaVvbgN6lR1ru+J09bUX6etqYJq4Z2LjieXt5rMkxn34sjnrzwFncK7br9736s33d//0LL9X2HMGI/+BysZfqgS/wmSAAAAAElFTkSuQmCC
// @include      /^(?!.*youtube.com).*/
// ==/UserScript==

// Turn light page to dark
var styles = `
html[gd_pagecheck]:not([gd_pagecheck="dark"]) {background:white!important}
html:not([gd_pagecheck="dark"]) body {background-image:unset!important}
html:not([gd_pagecheck="dark"]) * {text-shadow:0 0 .1px}
html:not([gd_pagecheck="dark"]),
html:not([gd_pagecheck="dark"]):after,
html:not([gd_pagecheck="dark"]) :is(img, embed, video, canvas, option, object, frame, :fullscreen:not(iframe), iframe:not(:fullscreen), body frameset) {filter:invert(1)hue-rotate(180deg)!important}
html:not([gd_pagecheck="dark"]) video:fullscreen{filter:unset!important}

// invert back image divs
html:not([gd_pagecheck="dark"]) body>* [style*="url("]:not([style*="cursor:"]):not([type="text"]){filter:invert(1)hue-rotate(180deg)!important}
html:not([gd_pagecheck="dark"]) video:fullscreen,
html:not([gd_pagecheck="dark"]) body>* [style*="url("]:not([style*="cursor:"]) :not(#⁠){filter:unset!important}
`

var styleSheet = document.createElement("style")
styleSheet.type = "text/css"
styleSheet.innerText = styles
document.head.appendChild(styleSheet)

// Detect page is whether light or dark
var styleSheet = document.createElement("style")
styleSheet.type = "text/css"
styleSheet.innerText = styles
document.head.appendChild(styleSheet)

// Detect page is whether light or dark
var v = getComputedStyle(document.querySelector("body"), null).getPropertyValue("background-color");
var m = v.match(/\d+/g);
var r = parseInt(m[0]);
var g = parseInt(m[1]);
var b = parseInt(m[2]);

if ((r + g + b) > 500 || v == 'rgba(0, 0, 0, 0)' && window.location == window.parent.location ) {
    document.querySelector('html').setAttribute("gd_pagecheck", "light");
} else if (window.location == window.parent.location ) {
    document.querySelector('html').setAttribute("gd_pagecheck", "dark");
}