全局暗模式

它只會將明亮的網站變為黑暗。

目前為 2022-05-22 提交的版本,檢視 最新版本

  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.05.22.21.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", () => {
  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. <div id="GDM_header">
  49. <div>
  50. <input id="GDM_Abt" type="radio" name="contact" checked="checked">
  51. <label class="GDM_label GDM_button" for="GDM_Abt">&#128712;</label>
  52. </div>
  53. <b>Global Darkmode</b>
  54. <div>
  55. <a id="GDM_save" class="GDM_button">&#10006;</a>
  56. </div>
  57. </div>
  58. <input id="GDM_Off" type="radio" name="contact"><label for="GDM_Off" class="GDM_tabButtons">On</label><!--
  59. --><input id="GDM_On" type="radio" name="contact"><label for="GDM_On" class="GDM_tabButtons">Off</label>
  60. <div id="GDM_content">
  61. <textarea id="GDM_Off_filter" spellcheck="false" placeholder="example.com,\nlotemipsum.com">`+OfURL+`</textarea>
  62. <textarea id="GDM_On_filter" spellcheck="false" placeholder="example.com,\nlotemipsum.com">`+OnURL+`</textarea>
  63. <div id="GDM_about">
  64. <div>
  65. <b>On</b> tab URLs always apply this theme.</br>
  66. <b>Off</b> tab URLs always do not apply.</br>
  67. URLs are separated by commas and line breaks.
  68. </div>
  69. <div class="GDM_about_inner GDM_about_inner_btm" style="position:absolute; bottom:5px">
  70. <a href="https://gf.qytechs.cn/scripts/434440/feedback" style="font-size: 12px">Suggestion & Bug Report</a></br>
  71. <a href="https://paypal.me/ndaesik" style="font-size: 12px">Devs paypal.me</a>
  72. </div>
  73. </div>
  74. </div>
  75. </div>
  76.  
  77. <style>
  78. #GDM_option * {all:initial}
  79. #GDM_option b {font-weight:bold!important}
  80. #GDM_option {background-color: #fff!important; height:430px; position: fixed; top: 25px; right: 25px; width: 309px; z-index: 2147483647; box-shadow: 0 -1px 2px 0 rgb(0 0 0 / 30%), 0 -2px 6px 2px rgb(0 0 0 / 15%); user-select: none; padding:8px}
  81. #GDM_option [type="radio"] {visibility:hidden; width: 0}
  82. #GDM_option [type="radio"]:checked+label:not([for="GDM_Abt"]) {opacity: 1; border-color:orange}
  83. #GDM_option label:not([for="GDM_Abt"]) {font-weight:bold; opacity:.3; height:27px; width:50%; background-color: #fff; display: inline-block; user-select: none; text-align: center!important; padding-top:5px; border-top:2px transparent solid}
  84. #GDM_option label:not([for="GDM_Abt"]):hover {background-color: #FFF!important; opacity:1}
  85. #GDM_save,#GDM_Abt~label {position: absolute; width: 25px; height: 25px; user-select: none; text-decoration: none!important; font-size:16px}
  86. #GDM_save {right:8px;text-align:right}
  87. #GDM_Abt~label:hover,#GDM_Abt:checked~label {color:orange}
  88. #GDM_Abt~label {left:8px}
  89. #GDM_header {display:inline-block!important; width:100%!important; height: 34px; text-align:center; font-weight:bold}
  90. #GDM_content>div {white-space: pre-line}
  91. #GDM_content>*{background-color: #FFF!important; height: 340px; padding: 5px 8px; font-size: 14px; width: calc(309px - 32px)}
  92. :is(#GDM_On,#GDM_Off):checked~#GDM_content #GDM_about,
  93. #GDM_content>textarea{display:none}
  94. #GDM_about>div {display:inline-block}
  95. #GDM_On:checked~#GDM_content #GDM_On_filter,
  96. #GDM_Off:checked~#GDM_content #GDM_Off_filter {display: block!important}
  97. #GDM_option a:hover {cursor: pointer; text-decoration:underline}
  98. </style>
  99. `)
  100. document.querySelector("#GDM_save").addEventListener("click", () => Lturn())
  101.  
  102. let bdyH0 = window.parent.document.body.offsetHeight == 0,
  103. frame = self != top,
  104. elems = document.querySelectorAll("body > :not(script)"),
  105. apply = () => document.head.appendChild(drkMo),
  106. togle = () => (document.querySelector(".drkMo") == null) ? apply() : document.querySelector(".drkMo").remove(),
  107. drkMo = document.createElement("style"),
  108. check = (m,m2=0) => {
  109. let n = (n) => {return parseInt(getComputedStyle(document.querySelectorAll(m)[m2]).getPropertyValue("background-color").match(/\d+/g)[n])};
  110. return (n(0)*0.299+n(1)*0.587+n(2)*0.114) > 186 || n(3) == 0 }
  111. drkMo.innerText = `
  112. html {color-scheme:dark!important;color:#000}
  113. html * {color-scheme:light!important;text-shadow:0 0 .1px}
  114. html body {background:none!important}
  115. html, html :is(i, img, image, embed, video, canvas, option, object, :fullscreen:not(iframe), iframe:not(:fullscreen)),
  116. html body>* [style*="url("]:not([style*="cursor:"]):not([type="text"]) {filter:invert(1)hue-rotate(180deg)!important}
  117. html body>* [style*="url("]:not([style*="cursor:"]) :not(#⁠),
  118. html:not(#⁠) :is(canvas, option, object) :is(i, img, image, embed, video),
  119. html:not(#⁠) video:fullscreen{filter:unset!important}`
  120. drkMo.classList.add("drkMo")
  121. document.querySelector(".PRE")?.remove()
  122. if(WLrun) {apply()} else
  123. if(BLrun) {
  124. if((!frame && !bdyH0 || frame) && check("html") && check("body")) apply()
  125. if(!frame && bdyH0) {for (let i = 0; i < elems.length ; i++) {if (elems[i].scrollHeight > window.innerHeight && check("body > :not(script)",i)) apply()}}
  126. }
  127. GM_registerMenuCommand("On/Off", togle)
  128. GM_registerMenuCommand("Filter", Lturn)
  129. })()})

QingJ © 2025

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