// ==UserScript== // @name:ko 스마트 다크 모드 // @name Smart Dark Mode // @name:ru Умный темный режим // @name:ja スマートダークモード // @name:zh-TW 智能暗黑模式 // @name:zh-CN 智能暗黑模式 // @description:ko 밝은 색의 웹 사이트들만 어둡게 만듭니다. // @description Turn only bright websites to dark. // @description:ru Делайте темными только яркие сайты. // @description:ja 明るいウェブサイトだけを暗くします。 // @description:zh-TW 它只會將明亮的網站變為黑暗。 // @description:zh-CN 它只会将明亮的网站变为黑暗。 // @namespace https://ndaesik.tistory.com/ // @version 2022.06.30.10.20 // @author ndaesik // @icon https://lh3.googleusercontent.com/81tKJiCnAHzX1YojaGl1h33INWH-PcMN7S1N5eaTf4aUyO5Y7iKJ4cTI8JcZL55iP4bbWyFsJWfFrX4Doe-KaXaI0g // @match *://*/* // @grant GM.getValue // @grant GM.setValue // @grant GM_registerMenuCommand // @run-at document-start // @downloadURL none // ==/UserScript== // prevent blink if (self == top) { let preventBlinkCSS = document.createElement('style') preventBlinkCSS.innerText = `* {background:#202124!important; border-color:#3c4043!important; color-scheme:dark!important; color:#bdc1c6!important}` preventBlinkCSS.classList.add('preventBlinkCSS') document.head?.appendChild(preventBlinkCSS) } // main.js window.addEventListener('load', _ => { (async _ => { let alwaysOnList = await GM.getValue('alwaysOnList', ''); let alwaysOffList = await GM.getValue('alwaysOffList', 'youtube.com/live_chat?'); let checkUrlExist = list => { return (list.replaceAll(/\s/g,'').split(/[\r\n]+|,/g) != '' && list.replaceAll(/\s/g,'').split(/[\r\n]+|,/g).filter(a => window.document.URL.indexOf(a) > -1).length > 0) ? true : false } let saveTextarea = _ => { GM.setValue('alwaysOnList', document.querySelector('#GDM_on_textarea').value.replace(/^, ?/, '')); GM.setValue('alwaysOffList', document.querySelector('#GDM_off_textarea').value.replace(/^, ?/, '')); } let toggleOption = _ => { let e = document.querySelector('#GDM_body'); if (e.style.display == 'none') { e.style.display = 'block'; } else { e.style.display = 'none'; saveTextarea() } } let applyFilter = _ => document.head.appendChild(drkMo); let toggleFilter = _ => { if (document.querySelector('style.drkMo') == null) { applyFilter(); document.querySelector('#GDM_toggle').checked = true; } else { document.querySelectorAll('style.drkMo').forEach(e => e.remove()); document.querySelector('#GDM_toggle').checked = false; } } // add option div in DOM document.body.insertAdjacentHTML('beforeend', `
`) // color inverter CSS let drkMo = document.createElement('style') drkMo.innerText = ` html {color-scheme: dark!important; color: #000} html * {color-scheme: light!important; text-shadow: 0 0 .1px} html body {background: none!important} #GDM_body, html, html :is(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(#_mostImportant_), html:not(#_mostImportant_) :is(canvas, option, object) :is(img, image, embed, video), html:not(#_mostImportant_) video:fullscreen{filter: unset!important}` drkMo.classList.add('drkMo') // apply main CSS document.querySelector('.preventBlinkCSS')?.remove() if( checkUrlExist( alwaysOnList ) ) { applyFilter() } else if ( checkUrlExist( alwaysOffList ) ) { // do nothing } else { let bdyH0 = window.parent.document.body.offsetHeight == 0; let frame = self != top; let elems = document.querySelectorAll('body > :not(script)'); let check = (o, t = 0) => { let n = n => {return parseInt(getComputedStyle(document.querySelectorAll(o)[t]).getPropertyValue('background-color').match(/\d+/g)[n])}; return (n(0)*0.299+n(1)*0.587+n(2)*0.114) > 186 || n(3) == 0; } if((!frame && !bdyH0 || frame) && check('html') && check('body')) applyFilter(); if(!frame && bdyH0) {for (let i = 0; i < elems.length; i++) {if (elems[i].scrollHeight > window.innerHeight && check('body > :not(script)',i)) applyFilter()}}; } // GDM_toggle function document.querySelector('style.drkMo') ? (document.querySelector('#GDM_toggle').checked = true) : (document.querySelector('#GDM_toggle').checked = false); document.querySelector('#GDM_toggle').onclick = _ => toggleFilter(); // GDM_add_page function document.querySelector('#GDM_add_page').onclick = _ => { let domain = `, ${new URL(document.URL).hostname.replace('www.','')}`; if (document.querySelector('#GDM_on_tab_button:checked') != null) {document.querySelector('#GDM_on_textarea').value += domain}; if (document.querySelector('#GDM_off_tab_button:checked') != null) {document.querySelector('#GDM_off_textarea').value += domain}; saveTextarea() } // GDM_close_window function document.querySelector('#GDM_close_window').onclick = _ => toggleOption(); // GDM_about_tab description function fillDescription() { switch (window.navigator.language) { case 'ko': return `"On" 탭 URL은 테마를 적용하지만 "Off" 탭은 적용하지 않습니다.\n도메인은 쉼표와 줄 바꿈으로 구분됩니다.`; case 'zh-TW': case 'zh-HK': case 'zh-SG': return `" On" 標籤 URL 應用主題但不應用" Off" 標籤 。\n域分爲逗號和換行 。`; case 'es': return `La URL de la pestaña "On" aplica el tema, pero la pestaña "Off" no.La línea principal se divide en coma y cambio de línea.`; case 'fr': return `L'URL de l'onglet On applique le thème, mais pas l'onglet Off.\nLes domaines sont séparés par des virgules et des lignes.`; case 'de': return `Die URL der Registerkarte "On" setzt das Thema an, aber nicht die Registerkarte "Off".\nDomains werden durch Kommata und Zeilenumbrüche getrennt.`; case 'it': return `La scheda "On" URL applica il tema, ma non la scheda "Off".\nI domini sono separati da una virgola e da un'interruzione di riga.`; case 'vi': return `URL của tab "On" áp dụng chủ đề nhưng tab "Off" không áp dụng.\nDomain được phân loại bằng dấu phẩy và thay đổi dòng.`; case 'th': return `ที่อยู่ URL ของแท็บ "On" ใช้ธีม แต่ไม่ใช้แท็บ "Off"\nโดเมนถูกแบ่งออกเป็นลูกน้ำและการสลับบรรทัด`; case 'id': return `URL tab "On" menerapkan tema, namun tab "Off" tidak diterapkan.\nDomain terbagi menjadi koma dan perubahan baris.`; case 'zh-CN': return `" On" 标签 URL 应用主题但不应用" Off" 标签 。\n域分为逗号和换行 。`; case 'ja': return `"On"タブURLはテーマを適用しますが、"Off"タブは適用されません。\nドメインはコンマと行違いに区分されます。`; case 'ru': return `URL вкладки "On" применяет тему, но вкладка "Off" не применяется.\ndomain делится на запятую и запятую.`; default: return `"On" tab URLs apply themes, but not "Off" tab URLs.\nDomains are separated by commas and line breaks.`; } } document.querySelector('#GDM_about_tab').textContent = fillDescription(); // tampermonkey menu GM_registerMenuCommand('On/Off', toggleFilter); GM_registerMenuCommand('Filter', toggleOption); })()})