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

Commit

Permalink
- Fix content of pages was not interactive (clickable)
Browse files Browse the repository at this point in the history
- Fix add-on not working if user is logged out
  • Loading branch information
krisztianb committed Aug 24, 2024
1 parent f16bd0a commit b73d7e3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 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.4",
"version": "1.5",
"description": "Removes the paywall from news and article pages on the seekingalpha.com website",
"icons": {
"48": "icons/48x48.png",
Expand Down
27 changes: 22 additions & 5 deletions paywall-remover.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,17 @@
const payWallSelector = "main + div > div + div";
const overlaySelector = "div.bg-black\\/30";
const contentWrapperSelector = "#content";
let matchingPayWallSelector = "";

/**
* The structure of the HTML (and the pay wall) is not always the same.
* So we need to check different possible pay wall locations on the page.
* The matching selector is stored in the variable "matchingPayWallSelector".
*/
const payWallSelectors = [
"main + div > div + div", // user is logged in
"main article div.contents + div", // user is not logged in
];

const overlaySelector = "div.bg-black\\/30"; // this is the element creating the gray semi-transparent overlay effect
const contentWrapperSelector = ".contents";
const articleSelector = "main article section";

// Store the original non-pay-walled content
Expand All @@ -9,7 +20,13 @@ const content = document.querySelector(articleSelector).innerHTML;
// Code executed once the paywall is shown
new window.MutationObserver(function (mutations) {
for (const mutation of mutations) {
if (mutation.target.matches(payWallSelector)) {
payWallSelectors.forEach((selector) => {
if (mutation.target.matches(selector)) {
matchingPayWallSelector = selector;
}
});

if (matchingPayWallSelector) {
removeBodyScrollLock();
hidePayWall();
restoreContent();
Expand All @@ -29,7 +46,7 @@ new window.MutationObserver(function (mutations) {
}).observe(document, { subtree: true, attributes: true });

function hidePayWall() {
const payWallDialog = document.querySelector(payWallSelector);
const payWallDialog = document.querySelector(matchingPayWallSelector);
if (payWallDialog) {
payWallDialog.setAttribute("style", "display:none");
}
Expand Down

0 comments on commit b73d7e3

Please sign in to comment.