Greasyfork No Dark Mode

Disables dark mode on Greasyfork/Sleazyfork.

  1. // ==UserScript==
  2. // @name Greasyfork No Dark Mode
  3. // @description Disables dark mode on Greasyfork/Sleazyfork.
  4. // @icon https://greatest.deepsurf.us/vite/assets/blacklogo96-CxYTSM_T.png
  5. // @version 1.1
  6. // @author afkarxyz
  7. // @namespace https://github.com/afkarxyz/userscripts/
  8. // @supportURL https://github.com/afkarxyz/userscripts/issues
  9. // @license MIT
  10. // @match https://greatest.deepsurf.us/*
  11. // @match https://sleazyfork.org/*
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15.  
  16. (function () {
  17. 'use strict';
  18.  
  19. function removeDarkModeCSS() {
  20. for (let i = 0; i < document.styleSheets.length; i++) {
  21. const sheet = document.styleSheets[i];
  22.  
  23. try {
  24. const rules = sheet.cssRules;
  25. if (!rules) continue;
  26.  
  27. for (let j = rules.length - 1; j >= 0; j--) {
  28. const rule = rules[j];
  29. if (
  30. rule.type === CSSRule.MEDIA_RULE &&
  31. rule.conditionText.includes('prefers-color-scheme: dark')
  32. ) {
  33. sheet.deleteRule(j);
  34. }
  35. }
  36. } catch (e) {
  37. continue;
  38. }
  39. }
  40. }
  41.  
  42. function observeStyleChanges() {
  43. const observer = new MutationObserver(() => {
  44. removeDarkModeCSS();
  45. });
  46.  
  47. observer.observe(document.documentElement, {
  48. childList: true,
  49. subtree: true
  50. });
  51. }
  52.  
  53. removeDarkModeCSS();
  54. observeStyleChanges();
  55.  
  56. if (document.readyState === 'loading') {
  57. document.addEventListener('DOMContentLoaded', removeDarkModeCSS);
  58. } else {
  59. removeDarkModeCSS();
  60. }
  61. })();