Skip to content
This repository has been archived by the owner on Nov 27, 2024. It is now read-only.

Commit

Permalink
- Use mutation observer to determine if page content has been loaded
Browse files Browse the repository at this point in the history
- Make scroll lock removal more forceful
  • Loading branch information
krisztianb committed Oct 2, 2024
1 parent 4ced98a commit 4ea00a0
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Seeking Alpha Paywall Remover",
"version": "1.9",
"version": "1.10",
"description": "Removes the paywall from news and article pages on the seekingalpha.com website",
"icons": {
"48": "icons/48x48.png",
Expand Down
31 changes: 12 additions & 19 deletions paywall-remover.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ let matchingPayWallSelector = "";
let content = ""; // Stores the original full non-pay-walled content

// Code checking if the page has finished loading the full content
let fullArticleLoadedCheck = setInterval(() => {
new window.MutationObserver(() => {
// Here we assume that the page contains at least one paragraph
const hasFullArticleLoaded = document.querySelector("p.paywall-full-content") != null;

if (hasFullArticleLoaded) {
removePayWallMarkersFromPage();
storeContent();
preparePayWallRemover();
clearInterval(fullArticleLoadedCheck);
this.disconnect();
}
}, 10);
}).observe(document, { subtree: true, childList: true });

// Code checking if the paywall has been displayed
function preparePayWallRemover() {
// Code checking if the paywall has been displayed
let payWallLoadedCheck = setInterval(() => {
payWallSelectors.forEach((selector) => {
const payWall = document.querySelector(selector);
Expand All @@ -48,9 +48,13 @@ function preparePayWallRemover() {
}

// Code that keeps removing interactivity locks from the page
setInterval(() => {
removeInteractivityLock();
}, 2500);
new window.MutationObserver(function (mutations) {
for (const mutation of mutations) {
if (mutation.target.matches("*[inert]")) {
mutation.target.removeAttribute("inert");
}
}
}).observe(document, { subtree: true, attributes: true });

function hidePayWall() {
const payWallDialog = document.querySelector(matchingPayWallSelector);
Expand All @@ -66,21 +70,10 @@ function hidePayWall() {

function removeBodyScrollLock() {
const body = document.body;

["lockScroll", "scrollLock"].forEach((className) => {
body.classList.remove(className);
});

body.removeAttribute("class"); // has a class that blocks scrolling
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 removePayWallMarkersFromPage() {
// This is necessary because otherwise a script on the page will keep removing the marked content once we restore it
["paywall-full-content", "invisible"].forEach((className) => {
Expand Down

0 comments on commit 4ea00a0

Please sign in to comment.