Skip to content

Commit

Permalink
Correctly check if metaElement exist in callbackTitle. Rename callbba…
Browse files Browse the repository at this point in the history
…ck to callbackDirectAccess to differentiate the two callbackes. Removing useless check in isPremium function
  • Loading branch information
Write committed Sep 1, 2024
1 parent d8c2eb8 commit 25e76c5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions ophirofox/content_scripts/lesechos.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,14 @@ async function onLoad() {
*/

const isPremium = (metaElement) => {
if (metaElement && metaElement.content === 'subscribers') {
if (metaElement.content == 'subscribers') {
return true;
}
return false;
};

// Observer [ Direct URL Access ]
const callback = (mutationList, observer) => {
const callbackDirectAccess = (mutationList, observer) => {
const metaElement = document.querySelector('meta[name="ad:postAccess"]');
if (metaElement) {
if (isPremium(metaElement)) {
Expand All @@ -45,7 +45,7 @@ async function onLoad() {
}
for (const mutation of mutationList) {
for (const e of mutation.addedNodes) {
if (e.name === "ad:postAccess") {
if (e.name == "ad:postAccess") {
if (isPremium(e)) {
addEuropresseButton();
}
Expand All @@ -56,8 +56,8 @@ async function onLoad() {
}
};

const observer = new MutationObserver(callback);
observer.observe(document.body, {
const observerDirectAccess = new MutationObserver(callbackDirectAccess);
observerDirectAccess.observe(document.body, {
childList: true,
subtree: false
});
Expand All @@ -66,8 +66,10 @@ async function onLoad() {
const callbackTitle = (mutationList, observer) => {
buttonAdded = false;
const metaElement = document.querySelector('meta[name="ad:postAccess"]');
if (isPremium(metaElement)) {
addEuropresseButton();
if (metaElement) {
if (isPremium(metaElement)) {
addEuropresseButton();
}
}
};

Expand Down

0 comments on commit 25e76c5

Please sign in to comment.