Global Darkmode

Turn in bright websites to dark.

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

  1. // ==UserScript==
  2. // @name Global Darkmode
  3. // @description Turn in bright websites to dark.
  4.  
  5. // @name:ko 글로벌 다크모드
  6. // @description:ko 밝은 색의 웹 사이트들을 어둡게 만듭니다.
  7.  
  8. // @namespace https://ndaesik.tistory.com/
  9. // @version 2021.11.02.13:42
  10. // @author ndaesik
  11. // @icon https://www.iconsdb.com/icons/preview/gray/moon-4-xxl.png
  12. // @include *
  13. // ==/UserScript==
  14.  
  15. // Turn light page to dark
  16. var styles = `
  17. html[w_root] {background:#FFF!important}
  18. html[white] body {background:none!important}
  19. html[white] * {text-shadow:0 0 .1px}
  20. html[white],
  21. html[white] :is(i, img, image, embed, video, canvas, option, object, frame, :fullscreen:not(iframe), iframe:not(:fullscreen), body frameset),
  22. html[white] body>* [style*="url("]:not([style*="cursor:"]):not([type="text"]) {filter:invert(1)hue-rotate(180deg)!important}
  23. html[white] video:fullscreen,
  24. html[white] body>* [style*="url("]:not([style*="cursor:"]) :not(#⁠){filter:unset!important}
  25.  
  26. html[white]:not(#⁠) :is(canvas, option, object, frame, body frameset) :is(i, img, image, embed, video),
  27. html[white]:not(#⁠) video:fullscreen{filter:unset!important}
  28. `
  29.  
  30. const styleSheet = document.createElement("style")
  31. styleSheet.type = "text/css"
  32. styleSheet.innerText = styles
  33. document.head.appendChild(styleSheet)
  34.  
  35. // Detect page is whether light or dark
  36. function wd(target) {
  37. const v = getComputedStyle(document.querySelector(target), null).getPropertyValue("background-color").match(/\d+/g);
  38. const c = (parseInt(v[0]) + parseInt(v[1]) + parseInt(v[2])) > 500 || parseInt(v[3]) == 0; // get sum of rgb and check | return true when it's invisible
  39. if ( c == true ) { return true; }
  40. return false;
  41. }
  42. function n(n){document.documentElement.setAttribute(n, "");}
  43.  
  44. // set attribute
  45. if ( self === top ) {
  46. if ( wd("html") && wd("body") && window.parent.document.body.offsetHeight !== 0 ) { n("white"); n("w_root"); }
  47. else;
  48. };
  49.  
  50. if ( self !== top ) {
  51. if ( window.parent.document.querySelector('html[w_root]') !== null && !( wd("html") && wd("body") ));
  52. else n("white");
  53. };
  54.  
  55. if (window.parent.document.body.offsetHeight == 0) {
  56. let max;
  57. document.querySelectorAll('body > *').forEach(e=>{
  58. if (max == null) max = e;
  59. else if (e.scrollHeight > max.scrollHeight) max = e;
  60. });
  61. const v2 = getComputedStyle(max, null).getPropertyValue("background-color").match(/\d+/g);
  62. const c2 = (parseInt(v2[0]) + parseInt(v2[1]) + parseInt(v2[2])) > 500 || parseInt(v2[3]) == 0;
  63. if ( c2 == true ) n("white");
  64. else;
  65. }

QingJ © 2025

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