reddit default theme

Disable reddit custom subreddits themes, fallback to the default one.

  1. // ==UserScript==
  2. // @name reddit default theme
  3. // @description Disable reddit custom subreddits themes, fallback to the default one.
  4. // @namespace https://greasyfork.org/scripts/29326
  5. // @include http://www.reddit.com/*
  6. // @include https://www.reddit.com/*
  7. // @include http://np.reddit.com/*
  8. // @include https://np.reddit.com/*
  9. // @include http://xm.reddit.com/*
  10. // @include https://xm.reddit.com/*
  11. // @version 2
  12. // @grant none
  13. // @run-at document-start
  14. // ==/UserScript==
  15. 'use strict';
  16.  
  17. function find_and_delete_theme(node)
  18. {
  19. if (node.nodeType === Node.ELEMENT_NODE &&
  20. node.nodeName.toLowerCase() === 'link' &&
  21. node.getAttribute('rel') === 'stylesheet' &&
  22. node.getAttribute('title') === 'applied_subreddit_stylesheet') {
  23. node.parentNode.removeChild(node);
  24. return true;
  25. }
  26. }
  27.  
  28. function delete_if_present()
  29. {
  30. if (document.head) {
  31. for (var node of document.head.childNodes) {
  32. if (find_and_delete_theme(node))
  33. return true;
  34. }
  35. }
  36. }
  37.  
  38. function delete_when_inserted()
  39. {
  40. (new MutationObserver(function(records, observer) {
  41. for (var record of records) {
  42. for (var node of record.addedNodes) {
  43. if (find_and_delete_theme(node)) {
  44. observer.disconnect();
  45. return;
  46. }
  47. }
  48. }
  49. })).observe(document, {childList: true, subtree: true});
  50. }
  51.  
  52. delete_if_present() || delete_when_inserted();