Greasy Fork 支持 简体中文。

dark mode

Auto Dark Mode

目前為 2024-05-07 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name dark mode
  3. // @description Auto Dark Mode
  4. // @version 1.0
  5. // @author Anc
  6. // @match *://*/*
  7. // @exclude *://*localhost*
  8. // @exclude *://*127.0.0.1*
  9. // @exclude *://*sspai.*
  10. // @exclude *://*github.*
  11. // @exclude *://*v2ex.com/*
  12. // @exclude *://*appinn.*
  13. // @exclude *://*twitter.*
  14. // @exclude *://*192.168.*
  15. // @exclude *://*gcores.*
  16. // @exclude *://*ithome.com/*
  17. // @exclude *://*reddit.com/*
  18. // @exclude *://*mp.weixin.qq.com/*
  19. // @exclude *://wifi.airchina.com/*
  20. // @exclude *://rebang.today/*
  21. // @exclude *://m.hupu.com/*
  22. // @exclude *://m.douyin.com/*
  23. // @exclude *://ddys.tv/*
  24. // @exclude *://www.mvcat.com/*
  25. // @exclude *://pan.quark.cn/*
  26. // @exclude *://ddys.*
  27. // @exclude *://*ecosia.org/*
  28. // @exclude *://vr.akan.com.cn/h5/app/*
  29. // @exclude *://*steamcommunity.com/*
  30. // @exclude *://www.greenmangaming.com/*
  31. // @exclude *://chat.openai.com/*
  32. // @exclude *://learn.microsoft.com/*
  33. // @exclude *://app.gamersky.com/*
  34. // @exclude *://*.epicgames.com/*
  35. // @exclude *://paipai.m.jd.com/*
  36. // @exclude *://*bing.com/*
  37. // @run-at document.start
  38. // @grant GM.addStyle
  39. // @grant GM_registerMenuCommand
  40. // @grant GM_setValue
  41. // @grant GM_getValue
  42. // @noframes
  43. // @namespace https://greasyfork.org/users/61607
  44. // ==/UserScript==
  45.  
  46. (function() {
  47. 'use strict';
  48. // Add meta tag
  49. let meta = document.createElement('meta');
  50. meta.name = "theme-color";
  51. meta.content = "#000";
  52. meta.media = "(prefers-color-scheme: dark)";
  53. document.head.append(meta);
  54.  
  55. // Function to create a button
  56. function createButton() {
  57. var button = document.createElement('button');
  58. button.textContent = 'White';
  59.  
  60. button.style.position = 'fixed';
  61. button.style.top = '10px';
  62. button.style.right = '10px';
  63. button.style.padding = '10px';
  64. button.style.backgroundColor = '#007bff';
  65. button.style.color = '#ffffff';
  66. button.style.border = 'none';
  67. button.style.borderRadius = '5px';
  68. button.style.cursor = 'pointer';
  69. button.style.zIndex = '999';
  70.  
  71. document.body.appendChild(button);
  72.  
  73. button.addEventListener('click', function() {
  74. var elements = document.getElementsByTagName('*');
  75.  
  76. for (var i = 0; i < elements.length; i++) {
  77. elements[i].style.filter = 'unset';
  78. }
  79. });
  80. }
  81.  
  82.  
  83. // Function to add the current website's domain to the array and save it
  84. function addDomainToArray() {
  85. var domain = window.location.hostname;
  86. var trackedDomains = GM_getValue('trackedDomains', []);
  87.  
  88. // Check if domain already exists in the array
  89. var index = trackedDomains.indexOf(domain);
  90. if ( index === -1) {
  91. trackedDomains.push(domain);
  92. GM_setValue('trackedDomains', trackedDomains);
  93. console.log('Domain ' + domain + ' added to tracking list.');
  94. } else {
  95. console.log('Domain ' + domain + ' is already in tracking list, remove it.');
  96. trackedDomains.splice(index, 1);
  97. GM_setValue('trackedDomains', trackedDomains);
  98. console.log("trackedDomains", trackedDomains);
  99. }
  100. }
  101.  
  102. // Function to check if the current domain is in the array and alert if so
  103. function checkDomain() {
  104. var domain = window.location.hostname;
  105. var trackedDomains = GM_getValue('trackedDomains', []);
  106. console.log("trackedDomains", trackedDomains);
  107.  
  108. if (trackedDomains.indexOf(domain) !== -1){
  109. console.log('You are visiting a tracked domain: ' + domain);
  110.  
  111. // Add style
  112. GM.addStyle(`
  113. @media (prefers-color-scheme: dark) {
  114. :root {
  115. filter: invert(1) hue-rotate(180deg);
  116. }
  117. figure,img,video,iframe,div[style*=image]{
  118. filter: invert(1) hue-rotate(180deg);
  119. opacity:1;
  120. }
  121.  
  122. figure img {
  123. filter: unset;
  124. }
  125. }
  126. `)
  127.  
  128. if(window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches) {
  129. createButton();
  130. }
  131.  
  132. }
  133. }
  134.  
  135. // Register a menu command to add the current domain to the tracking list
  136. GM_registerMenuCommand('Add/Reomove', addDomainToArray);
  137.  
  138. // Check the domain when the page loads
  139. checkDomain();
  140. })();