A Universal Dark Theme

Universal Dark Mode to fix flashbang sites like fitgirl repacks or wikipedia

  1. // ==UserScript==
  2. // @name A Universal Dark Theme
  3. // @description Universal Dark Mode to fix flashbang sites like fitgirl repacks or wikipedia
  4. // @match *://*/*
  5. // @grant GM_registerMenuCommand
  6. // @grant GM_setValue
  7. // @grant GM_getValue
  8. // @run-at document-idle
  9. // @version 2.0
  10. // @author TallTacoTristan
  11. // @license MIT
  12. // @namespace https://gf.qytechs.cn/users/1253611
  13. // ==/UserScript==
  14. function applyDarkTheme() {
  15. var style = document.createElement('style');
  16. style.innerHTML = `
  17. body, p, span, div, a, h1, h2, h3, h4, h5, h6, li, td:not(video) {
  18. color: #008080!important;
  19. }
  20. body, p, span, div, a, h1, h2, h3, h4, h5, h6, li, td[style*='background-image'] {
  21. background-color: #000000!important;
  22. background-image: none!important;
  23. }
  24. input[type='text'], input[type='password'], textarea, select {
  25. background-color: #D8BFD8!important;
  26. position: relative;
  27. z-index: 9999;
  28. }
  29. /* Add this rule to change non-interactable elements to black */
  30. body *:not(input[type='text']):not(input[type='password']):not(textarea):not(select) {
  31. background-color: #000000!important;
  32. color: #008080!important;
  33. }
  34. `;
  35. document.head.appendChild(style);
  36. }
  37.  
  38. // Check if the current hostname is excluded
  39. if (!(localStorage.getItem("excluded") === window.location.hostname)) {
  40. applyDarkTheme();
  41. }
  42.  
  43. // Create your button element
  44. var includeButton = document.createElement('button');
  45. includeButton.innerHTML = 'Include';
  46.  
  47. var excludeButton = document.createElement('button');
  48. excludeButton.innerHTML = 'Exclude';
  49.  
  50. // Append the buttons to the body of the page
  51. var buttonContainer = document.createElement('div');
  52. buttonContainer.style.position = 'fixed';
  53. buttonContainer.style.top = '10px';
  54. buttonContainer.style.right = '10px';
  55. buttonContainer.style.zIndex = '9999';
  56. buttonContainer.appendChild(includeButton);
  57. buttonContainer.appendChild(excludeButton);
  58. document.body.appendChild(buttonContainer);
  59.  
  60. // Add functionality to the buttons
  61. includeButton.addEventListener('click', function() {
  62. localStorage.removeItem("excluded", window.location.hostname); //make sure this matches
  63. location.reload();
  64. });
  65.  
  66. excludeButton.addEventListener('click', function() {
  67. localStorage.setItem("excluded", window.location.hostname); // Change "excluded" to something else if multiple userscripts use this code
  68. location.reload();
  69. });
  70.  
  71. // Check the localStorage for the user's preference
  72. var showButtons = GM_getValue('showButtons', true);
  73. buttonContainer.style.display = showButtons? 'block' : 'none';
  74.  
  75. // Register the GM menu commands
  76. GM_registerMenuCommand("Hide Buttons", function() {
  77. buttonContainer.style.display = 'none';
  78. GM_setValue('showButtons', false);
  79. }, 'h');
  80.  
  81. GM_registerMenuCommand("Show Buttons", function() {
  82. buttonContainer.style.display = 'block';
  83. GM_setValue('showButtons', true);
  84. },'s');
  85.  
  86. GM_registerMenuCommand("Include Current Site", function() {
  87. localStorage.removeItem("excluded", window.location.hostname);
  88. applyDarkTheme();
  89. });
  90.  
  91. GM_registerMenuCommand("Exclude Current Site", function() {
  92. localStorage.setItem("excluded", window.location.hostname); // Change "excluded" to something else if multiple userscripts use this code
  93. location.reload();
  94. });

QingJ © 2025

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