深色模式

适合几乎所有网站

目前为 2022-01-27 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name 深色模式
  3. // @namespace https://fcmsb250.github.io/
  4. // @version 0.2
  5. // @description 适合几乎所有网站
  6. // @author dsy
  7. // @match *://*/*
  8. // @grant GM_addStyle
  9. // @grant GM_getValue
  10. // @grant GM_registerMenuCommand
  11. // @grant GM_setValue
  12. // @run-at document-start
  13. // @license MIT
  14. // ==/UserScript==
  15.  
  16. (() => {
  17. var 改变值 = (值, 默认值, 回调) => {
  18. if (GM_getValue(值, 默认值) == "1") {
  19. GM_setValue(值, "0");
  20. } else if (GM_getValue(值, 默认值) == "0") {
  21. GM_setValue(值, "1");
  22. } else {
  23. GM_setValue(值, 默认值);
  24. }
  25. if (回调) {
  26. 回调();
  27. }
  28. };
  29. var 初始化值 = (值, 默认值, 回调) => {
  30. if (GM_getValue(值, "天知道是啥") == "天知道是啥") {
  31. GM_setValue(值, 默认值);
  32. }
  33. if (回调) {
  34. 回调();
  35. }
  36. };
  37. 初始化值("对图片视频等再次反色", "1");
  38. 初始化值("去部分网站背景图片", "0");
  39.  
  40. GM_registerMenuCommand("对图片视频等再次反色", () => {
  41. 改变值("对图片视频等再次反色", "1", () => {
  42. alert("刷新后生效");
  43. });
  44. });
  45. GM_registerMenuCommand("去背景图片", () => {
  46. 改变值("去背景图片", "0", () => {
  47. alert("刷新后生效");
  48. });
  49. });
  50. GM_registerMenuCommand("再来一次", () => {
  51. 再来一次();
  52.  
  53. if (GM_getValue("去背景图片") == "1") {
  54. document.body.style.backgroundImage = "none";
  55. document.documentElement.style.backgroundImage = "none";
  56. }
  57.  
  58. document.querySelectorAll("*").forEach((element) => {
  59. if (
  60. getComputedStyle(element).backgroundImage.indexOf("url") >= 0 &&
  61. element != document.body &&
  62. element != document.documentElement &&
  63. 对图片视频等再次反色
  64. ) {
  65. element.style.filter = "invert(1)";
  66. }
  67. });
  68. });
  69. })();
  70.  
  71. var 再来一次 = () => {
  72. "use strict";
  73. var css1 = `
  74. ::selection {
  75. color: white !important;
  76. background-color: white !important;
  77. }
  78. ::-webkit-scrollbar {
  79. background-color: black !important;
  80. }
  81. ::-webkit-scrollbar-thumb {
  82. background: rgb(100, 100, 100) !important;
  83. }
  84. html {
  85. text-shadow: 0 0 0 !important;
  86. background-color: white !important;
  87. }
  88. `;
  89. var css2 = `
  90. img,
  91. video,
  92. svg,
  93. canvas {
  94. filter: invert(1) !important;
  95. }
  96. `;
  97. var 对图片视频等再次反色 = GM_getValue("对图片视频等再次反色") == "1";
  98.  
  99. if (对图片视频等再次反色) {
  100. GM_addStyle(css2);
  101. }
  102. GM_addStyle(css1);
  103.  
  104. if (self == top) {
  105. GM_addStyle("html{ filter: invert(100%) brightness(0.3) !important; }");
  106. }
  107.  
  108. addEventListener("load", () => {
  109. if (GM_getValue("去背景图片") == "1") {
  110. document.body.style.backgroundImage = "none";
  111. document.documentElement.style.backgroundImage = "none";
  112. }
  113.  
  114. document.querySelectorAll("*").forEach((element) => {
  115. if (
  116. getComputedStyle(element).backgroundImage.indexOf("url") >= 0 &&
  117. element != document.body &&
  118. element != document.documentElement &&
  119. 对图片视频等再次反色
  120. ) {
  121. element.style.filter = "invert(1)";
  122. }
  123. });
  124. });
  125. };
  126.  
  127. 再来一次();

QingJ © 2025

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