From e6090768c513bb24530c89f35dd157c69f76d781 Mon Sep 17 00:00:00 2001 From: Krisztian Balla Date: Fri, 3 May 2024 11:43:30 +0200 Subject: [PATCH] Add code to remove interactivity lock --- paywall-remover.js | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/paywall-remover.js b/paywall-remover.js index b848ad2..6c2f920 100644 --- a/paywall-remover.js +++ b/paywall-remover.js @@ -1,8 +1,9 @@ const payWallSelector = 'div:has(> div[role="dialog"])'; -const contentSelector = "main article section"; +const contentWrapperSelector = "#content"; +const articleSelector = "main article section"; // Store the original non-pay-walled content -const content = document.querySelector(contentSelector).innerHTML; +const content = document.querySelector(articleSelector).innerHTML; // Code executed once the paywall is shown new window.MutationObserver(function (mutations) { @@ -16,15 +17,15 @@ new window.MutationObserver(function (mutations) { } }).observe(document, { subtree: true, childList: true }); -// Code that restores the content if it gets hidden by some additional script +// Code that removes the interactivity lock if it gets added by some script new window.MutationObserver(function (mutations) { for (const mutation of mutations) { - if (mutation.target.matches(contentSelector)) { - restoreContent(); + if (mutation.target.matches(contentWrapperSelector)) { + removeInteractivityLock(); this.disconnect(); } } -}).observe(document, { subtree: true, childList: true }); +}).observe(document, { subtree: true, attributes: true }); function hidePayWall() { const payWallOverlay = document.querySelector(payWallSelector); @@ -39,6 +40,13 @@ function removeBodyScrollLock() { body.removeAttribute("style"); // there is an additional "overflow:hidden" to remove } +function removeInteractivityLock() { + const deactivatedElements = document.querySelectorAll("*[inert]"); + deactivatedElements.forEach((element) => { + element.removeAttribute("inert"); + }); +} + function restoreContent() { - document.querySelector(contentSelector).innerHTML = content; + document.querySelector(articleSelector).innerHTML = content; }