Remove tp-modal-open on Technology Review

Removes the tp-modal-open class from <body> on load and DOM changes

  1. // ==UserScript==
  2. // @name Remove tp-modal-open on Technology Review
  3. // @description Removes the tp-modal-open class from <body> on load and DOM changes
  4. // @match https://www.technologyreview.com/*
  5. // @version 0.0.1.20250404080811
  6. // @namespace https://greasyfork.org/users/1435046
  7. // ==/UserScript==
  8.  
  9. (function() {
  10. 'use strict';
  11.  
  12. const removeOverflowFromClass = () => {
  13. for (const sheet of document.styleSheets) {
  14. let rules;
  15. try {
  16. rules = sheet.cssRules;
  17. } catch (e) {
  18. continue; // avoid CORS-restricted stylesheets
  19. }
  20.  
  21. if (!rules) continue;
  22.  
  23. for (const rule of rules) {
  24. if (
  25. rule.selectorText === 'body.tp-modal-open' ||
  26. rule.selectorText === '.tp-modal-open' ||
  27. rule.selectorText === 'body.tp-modal-open, .tp-modal-open'
  28. ) {
  29. if (rule.style && rule.style.overflow) {
  30. rule.style.removeProperty('overflow');
  31. }
  32. }
  33. }
  34. }
  35. };
  36.  
  37. // Run after DOM is ready
  38. if (document.readyState === 'loading') {
  39. document.addEventListener('DOMContentLoaded', removeOverflowFromClass);
  40. } else {
  41. removeOverflowFromClass();
  42. }
  43.  
  44. // Re-run when styles might be added dynamically
  45. const observer = new MutationObserver(removeOverflowFromClass);
  46. observer.observe(document.documentElement, {
  47. childList: true,
  48. subtree: true
  49. });
  50. })();