全局暗模式

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

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

  1. // ==UserScript==
  2. // @name:ko 글로벌 다크모드
  3. // @name Global Darkmode
  4. // @name:ru Глобальный темный режим
  5. // @name:jp グローバルダークモード
  6. // @name:zh-TW 全局暗模式
  7. // @name:zh-CN 全局暗模式
  8.  
  9. // @description:ko 밝은 색의 웹 사이트들만 어둡게 만듭니다.
  10. // @description Turn only bright websites to dark.
  11. // @description:ru Делайте темными только яркие сайты.
  12. // @description:jp 明るいウェブサイトだけを暗くします。
  13. // @description:zh-TW 它只會將明亮的網站變為黑暗。
  14. // @description:zh-CN 它只会将明亮的网站变为黑暗。
  15.  
  16. // @namespace https://ndaesik.tistory.com/
  17. // @version 2022.04.18.22:04
  18. // @author ndaesik
  19. // @icon data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg"><text x="-19vh" y="84vh" font-size="100vh">🪐</text></svg>
  20. // @match *://*/*
  21.  
  22. // @grant GM.getValue
  23. // @grant GM.setValue
  24. // @grant GM_registerMenuCommand
  25. // @run-at document-start
  26. // ==/UserScript==
  27. let PRE = document.createElement("style")
  28. PRE.innerText = `* {background:#202124!important; border-color:#3c4043!important; color-scheme:dark!important; color:#bdc1c6!important}`
  29. PRE.classList.add("PRE")
  30. self == top && document.head?.appendChild(PRE)
  31.  
  32. window.addEventListener("load", function(){
  33. (async () => {
  34. (await GM.getValue("OnURL") == undefined) ? GM.setValue("OnURL", "") : null;
  35. (await GM.getValue("OfURL") == undefined) ? GM.setValue("OfURL", "") : null;
  36. let OnURL = await GM.getValue("OnURL"),
  37. OfURL = await GM.getValue("OfURL"),
  38. BLrun = OnURL == "" || OnURL.replaceAll(/\s/g,"").split(/[\r\n]+|,/g).filter(w => window.document.URL.indexOf(w) > -1).length == 0,
  39. WLrun = OfURL != "" && OfURL.replaceAll(/\s/g,"").split(/[\r\n]+|,/g).filter(m => window.document.URL.indexOf(m) > -1).length != 0,
  40. Lturn = () => {
  41. let e = document.querySelector("#GDM_option");
  42. (e.style.display == "none")
  43. ? e.style.display = "block"
  44. : (e.style.display = "none", GM.setValue("OnURL", document.querySelector("#GDM_On_filter").value), GM.setValue("OfURL", document.querySelector("#GDM_Off_filter").value))
  45. }
  46. document.body.insertAdjacentHTML("beforeend", `
  47. <div id="GDM_option" style="display: none">
  48. <input id="GDM_Off" type="radio" name="contact"><label for="GDM_Off">On</label>
  49. <input id="GDM_On" type="radio" name="contact"><label for="GDM_On">Off</label>
  50. <input id="GDM_Abt" type="radio" name="contact" checked="checked"><label class="GDM_label GDM_button" for="GDM_Abt">About</label>
  51. <a id="GDM_save" class="GDM_button">❌</a>
  52. <div id="GDM_content">
  53. <textarea id="GDM_Off_filter" spellcheck="false" placeholder="example.com,\nlotemipsum.com">`+OfURL+`</textarea>
  54. <textarea id="GDM_On_filter" spellcheck="false" placeholder="example.com,\nlotemipsum.com">`+OnURL+`</textarea>
  55. <div id="GDM_about" style="display: none">On tab for set the site that always applies this theme.
  56. Off tab for set the site to which the theme is not applied.
  57. The filter list is separated by commas and line breaks.
  58. <div class="GDM_about_inner GDM_about_inner_btm" style="position:absolute; bottom:5px">
  59. <a href="https://gf.qytechs.cn/scripts/434440/feedback">Suggestion & Bug Report</a></br>
  60. <a href="https://paypal.me/ndaesik">Devs paypal.me</a>
  61. </div>
  62. </div>
  63. </div>
  64. </div>
  65.  
  66. <style>
  67. #GDM_option * {all:initial}
  68. #GDM_option {background-color: #6A6C6E!important; position: fixed; top: 25px; right: 25px; width: 375px; z-index: 2147483647; box-shadow: 0 0 0 1px hsl(0,0%,17.5%); user-select: none}
  69. #GDM_option [type="radio"] {visibility:hidden; width: 0}
  70. #GDM_option [type="radio"]:checked+label {font-weight:bold; background-color: #FFF!important}
  71. #GDM_option label {height:25px; width:90px; background-color: #6A6C6E; text-align: center; display: inline-block; width: 100px; user-select: none; text-align: center!important}
  72. #GDM_option label:hover {background-color: #FFF!important}
  73. #GDM_option #GDM_save {position: absolute; right: 0; user-select: none; text-decoration: none!important}
  74. #GDM_content>div {white-space : pre-line}
  75. #GDM_content>*{background-color: #FFF!important; min-height: 250px; padding: 5px 8px; font-size: 14px; display: none; width: 359px}
  76. #GDM_On:checked~#GDM_content #GDM_On_filter,
  77. #GDM_Off:checked~#GDM_content #GDM_Off_filter {display: block}
  78. #GDM_Abt:checked~#GDM_content #GDM_about {display: inline-block!important}
  79. #GDM_option a:hover {cursor: pointer; text-decoration:underline}
  80. </style>
  81. `)
  82. document.querySelector("#GDM_save").addEventListener("click", () => Lturn())
  83.  
  84. let bdyH0 = window.parent.document.body.offsetHeight == 0,
  85. frame = self != top,
  86. elems = document.querySelectorAll("body > :not(script)"),
  87. apply = () => document.head.appendChild(drkMo),
  88. togle = () => (document.querySelector(".drkMo") == null) ? apply() : document.querySelector(".drkMo").remove(),
  89. drkMo = document.createElement("style"),
  90. check = (m,m2=0) => {
  91. let n = (n) => {return parseInt(getComputedStyle(document.querySelectorAll(m)[m2]).getPropertyValue("background-color").match(/\d+/g)[n])};
  92. return (n(0)*0.299+n(1)*0.587+n(2)*0.114) > 186 || n(3) == 0 }
  93. drkMo.innerText = `
  94. html {color-scheme:dark!important;color:#000}
  95. html * {color-scheme:light!important;text-shadow:0 0 .1px}
  96. html body {background:none!important}
  97. html, html :is(i, img, image, embed, video, canvas, option, object, :fullscreen:not(iframe), iframe:not(:fullscreen)),
  98. html body>* [style*="url("]:not([style*="cursor:"]):not([type="text"]) {filter:invert(1)hue-rotate(180deg)!important}
  99. html body>* [style*="url("]:not([style*="cursor:"]) :not(#⁠),
  100. html:not(#⁠) :is(canvas, option, object) :is(i, img, image, embed, video),
  101. html:not(#⁠) video:fullscreen{filter:unset!important}`
  102. drkMo.classList.add("drkMo")
  103. document.querySelector(".PRE")?.remove()
  104. if(WLrun) {apply()} else
  105. if(BLrun) {
  106. if((!frame && !bdyH0 || frame) && check("html") && check("body")) apply()
  107. if(!frame && bdyH0) {for (let i = 0; i < elems.length ; i++) {if (elems[i].scrollHeight > window.innerHeight && check("body > :not(script)",i)) apply()}}
  108. }
  109. GM_registerMenuCommand("On/Off", togle)
  110. GM_registerMenuCommand("Filter", Lturn)
  111. })()});

QingJ © 2025

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