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

Commit 36200d7

Browse files
committed
Adjust code because page content is now loaded dynamically
1 parent 1ce0785 commit 36200d7

File tree

2 files changed

+40
-34
lines changed

2 files changed

+40
-34
lines changed

manifest.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 2,
33
"name": "Seeking Alpha Paywall Remover",
4-
"version": "1.6",
4+
"version": "1.7",
55
"description": "Removes the paywall from news and article pages on the seekingalpha.com website",
66
"icons": {
77
"48": "icons/48x48.png",

paywall-remover.js

+39-33
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
let matchingPayWallSelector = "";
2-
31
/**
42
* The structure of the HTML (and the pay wall) is not always the same.
53
* So we need to check different possible pay wall locations on the page.
@@ -12,41 +10,52 @@ const payWallSelectors = [
1210

1311
const overlaySelector = "div.bg-black\\/30"; // this is the element creating the gray semi-transparent overlay effect
1412
const contentWrapperSelector = ".contents";
15-
const articleSelector = "main article section";
13+
const contentSelector = "[data-test-id='content-container']";
1614
const adSelector = "main + div"; // might contain "special offer" ads
1715

18-
// Store the original non-pay-walled content
19-
const content = document.querySelector(articleSelector).innerHTML;
20-
21-
removeAds();
16+
let matchingPayWallSelector = "";
17+
let content = ""; // Stores the original full non-pay-walled content
2218

23-
// Code executed once the paywall is shown
19+
// Code executed once the loader has finished loading the full content
2420
new window.MutationObserver(function (mutations) {
2521
for (const mutation of mutations) {
26-
payWallSelectors.forEach((selector) => {
27-
if (mutation.target.matches(selector)) {
28-
matchingPayWallSelector = selector;
29-
}
30-
});
31-
32-
if (matchingPayWallSelector) {
33-
removeBodyScrollLock();
34-
hidePayWall();
35-
restoreContent();
22+
if (mutation.target.matches(contentSelector)) {
23+
storeContent();
24+
preparePayWallRemover();
3625
this.disconnect();
3726
}
3827
}
3928
}).observe(document, { subtree: true, childList: true });
4029

41-
// Code that removes the interactivity lock if it gets added by some script
42-
new window.MutationObserver(function (mutations) {
43-
for (const mutation of mutations) {
44-
if (mutation.target.matches(contentWrapperSelector)) {
45-
removeInteractivityLock();
46-
this.disconnect();
30+
function preparePayWallRemover() {
31+
// Code executed once the paywall is shown
32+
new window.MutationObserver(function (mutations) {
33+
for (const mutation of mutations) {
34+
payWallSelectors.forEach((selector) => {
35+
if (mutation.target.matches(selector)) {
36+
matchingPayWallSelector = selector;
37+
}
38+
});
39+
40+
if (matchingPayWallSelector) {
41+
removeBodyScrollLock();
42+
hidePayWall();
43+
restoreContent();
44+
this.disconnect();
45+
}
4746
}
48-
}
49-
}).observe(document, { subtree: true, attributes: true });
47+
}).observe(document, { subtree: true, childList: true });
48+
49+
// Code that removes the interactivity lock if it gets added by some script
50+
new window.MutationObserver(function (mutations) {
51+
for (const mutation of mutations) {
52+
if (mutation.target.matches(contentWrapperSelector)) {
53+
removeInteractivityLock();
54+
this.disconnect();
55+
}
56+
}
57+
}).observe(document, { subtree: true, attributes: true });
58+
}
5059

5160
function hidePayWall() {
5261
const payWallDialog = document.querySelector(matchingPayWallSelector);
@@ -73,13 +82,10 @@ function removeInteractivityLock() {
7382
});
7483
}
7584

76-
function restoreContent() {
77-
document.querySelector(articleSelector).innerHTML = content;
85+
function storeContent() {
86+
content = document.querySelector(contentSelector).innerHTML;
7887
}
7988

80-
function removeAds() {
81-
const ad = document.querySelector(adSelector);
82-
if (ad) {
83-
ad.remove();
84-
}
89+
function restoreContent() {
90+
document.querySelector(contentSelector).innerHTML = content;
8591
}

0 commit comments

Comments
 (0)