Remove tp-modal-open on Technology Review

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

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Remove tp-modal-open on Technology Review
// @description  Removes the tp-modal-open class from <body> on load and DOM changes
// @match        https://www.technologyreview.com/*
// @version 0.0.1.20250404080811
// @namespace https://greasyfork.org/users/1435046
// ==/UserScript==

(function() {
    'use strict';

    const removeOverflowFromClass = () => {
        for (const sheet of document.styleSheets) {
            let rules;
            try {
                rules = sheet.cssRules;
            } catch (e) {
                continue; // avoid CORS-restricted stylesheets
            }

            if (!rules) continue;

            for (const rule of rules) {
                if (
                    rule.selectorText === 'body.tp-modal-open' ||
                    rule.selectorText === '.tp-modal-open' ||
                    rule.selectorText === 'body.tp-modal-open, .tp-modal-open'
                ) {
                    if (rule.style && rule.style.overflow) {
                        rule.style.removeProperty('overflow');
                    }
                }
            }
        }
    };

    // Run after DOM is ready
    if (document.readyState === 'loading') {
        document.addEventListener('DOMContentLoaded', removeOverflowFromClass);
    } else {
        removeOverflowFromClass();
    }

    // Re-run when styles might be added dynamically
    const observer = new MutationObserver(removeOverflowFromClass);
    observer.observe(document.documentElement, {
        childList: true,
        subtree: true
    });
})();