From c23d1ea34cc0977420a4ded7b4fa6d176dba4a15 Mon Sep 17 00:00:00 2001 From: Calvin Wu Date: Mon, 30 Nov 2020 20:39:23 -0500 Subject: [PATCH] NYTimes fix (#1040) --- src/js/contentScript.js | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/js/contentScript.js b/src/js/contentScript.js index 1aff736..07ba122 100644 --- a/src/js/contentScript.js +++ b/src/js/contentScript.js @@ -262,19 +262,15 @@ if (matchDomain('elmercurio.com')) { } else if (matchDomain('nytimes.com')) { const previewButton = document.querySelector('.css-3s1ce0'); if (previewButton) { previewButton.click(); } - // Prevent bottom dock from appearing - new window.MutationObserver(function (mutations) { - for (const mutation of mutations) { - for (const node of mutation.addedNodes) { - if (node instanceof window.HTMLElement) { - if (node.matches('.css-3fbowa')) { - removeDOMElement(node); - this.disconnect(); - } - } - } + blockElement('.css-3fbowa'); // Prevent bottom dock from appearing + blockElement('#gateway-content'); // Remove paywall + blockElement('.css-1bd8bfl'); // Remove filter + // Restore scrolling + document.onreadystatechange = function () { + if (document.readyState === 'complete') { + document.querySelector('.css-mcm29f').setAttribute('style', 'position:relative'); } - }).observe(document, { subtree: true, childList: true }); + }; } else if (matchDomain('technologyreview.com')) { window.setTimeout(function () { const bodyObscured = document.querySelector('body[class*="body__obscureContent"]'); @@ -514,6 +510,22 @@ function pageContains (selector, text) { }); } +// Prevent element from being added to the DOM +function blockElement (selector) { + new window.MutationObserver(function (mutations) { + for (const mutation of mutations) { + for (const node of mutation.addedNodes) { + if (node instanceof window.HTMLElement) { + if (node.matches(selector)) { + removeDOMElement(node); + this.disconnect(); // Stop watching for element being added after one removal + } + } + } + } + }).observe(document, { subtree: true, childList: true }); +} + function NZHerald () { const video = document.querySelector('.video-js'); if (video) {