Skip to content

Commit 16998b7

Browse files
author
github-actions
committed
Release from Ophirofox v2.4.26325.5652
1 parent 6e0ad7c commit 16998b7

File tree

1 file changed

+51
-42
lines changed

1 file changed

+51
-42
lines changed

ophirofox.user.js

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// ==UserScript==
2-
// @version 2.4.26324.25526
2+
// @version 2.4.26325.5652
33
// @author Write
44
// @name OphirofoxScript
55
// @grant GM.getValue
@@ -1354,15 +1354,13 @@
13541354
return titleElem && titleElem.textContent;
13551355
}
13561356

1357-
let buttonAdded = false;
1358-
13591357
async function addEuropresseButton() {
1360-
if (!buttonAdded) {
1358+
const ophiroBtnPresence = document.querySelector('.ophirofox-europresse');
1359+
if (!ophiroBtnPresence) {
13611360
const elt = document.querySelector("button[aria-label=Commenter]")?.parentElement?.parentElement;
13621361
if (elt) {
13631362
const a = await ophirofoxEuropresseLink(extractKeywords());
13641363
elt.appendChild(a);
1365-
buttonAdded = true;
13661364
}
13671365
}
13681366
}
@@ -1374,54 +1372,57 @@
13741372
by a new meta with name ad:postAcces) and add the button (this is the first observer).
13751373
2. Or a page is newly routed (for instance, when one goes from the homepage to an article) :
13761374
- it is detected with the second observer that watches for changes in <title> and reset the button
1377-
- we wait for the end of actual loading of the new content by observing <main><meta content>.
1375+
- we wait for the end of actual loading of the new content by checking if meta[name="ad:postAccess"] exist.
13781376
*/
13791377

1380-
const isPremium = () => {
1381-
if (document.querySelector("meta[name='ad:postAccess']").content == 'subscribers') {
1378+
const isPremium = (metaElement) => {
1379+
if (metaElement.content == 'subscribers') {
13821380
return true;
13831381
}
13841382
return false;
13851383
};
13861384

1387-
const callback = (mutationList, observer) => {
1388-
if (document.querySelector('meta[name="ad:postAccess"]')) {
1389-
addEuropresseButton();
1385+
// Observer [ Direct URL Access ]
1386+
const callbackDirectAccess = (mutationList, observer) => {
1387+
const metaElement = document.querySelector('meta[name="ad:postAccess"]');
1388+
if (metaElement) {
1389+
if (isPremium(metaElement)) {
1390+
addEuropresseButton();
1391+
}
13901392
observer.disconnect();
13911393
return;
13921394
}
13931395
for (const mutation of mutationList) {
13941396
for (const e of mutation.addedNodes) {
13951397
if (e.name == "ad:postAccess") {
1396-
if (isPremium())
1398+
if (isPremium(e)) {
13971399
addEuropresseButton();
1400+
}
1401+
observer.disconnect();
1402+
return;
13981403
}
13991404
}
14001405
}
14011406
};
14021407

1403-
const observer = new MutationObserver(callback);
1404-
observer.observe(document.body, {
1405-
childList: true
1406-
});
1407-
1408-
const observerTitle = new MutationObserver(() => {
1409-
buttonAdded = false;
1410-
if (isPremium())
1411-
addEuropresseButton();
1412-
});
1413-
1414-
const title = document.querySelector("title")
1415-
observerTitle.observe(title, {
1408+
const observerDirectAccess = new MutationObserver(callbackDirectAccess);
1409+
observerDirectAccess.observe(document.body, {
14161410
childList: true,
14171411
subtree: false
14181412
});
14191413

1420-
const observerMain = new MutationObserver(() => {
1421-
addEuropresseButton();
1422-
});
1423-
const main = document.querySelector("main meta[content]")
1424-
observerMain.observe(main, {
1414+
// Observer [ Dynamic page Loading ]
1415+
const callbackDynamicLoading = (mutationList, observer) => {
1416+
const metaElement = document.querySelector('meta[name="ad:postAccess"]');
1417+
if (metaElement) {
1418+
if (isPremium(metaElement)) {
1419+
addEuropresseButton();
1420+
}
1421+
}
1422+
};
1423+
1424+
const observerDynamicLoading = new MutationObserver(callbackDynamicLoading);
1425+
observerDynamicLoading.observe(document.querySelector('title'), {
14251426
childList: true,
14261427
subtree: false
14271428
});
@@ -1862,17 +1863,22 @@
18621863
if ("https://www.nouvelobs.com/*".includes(hostname)) {
18631864

18641865
window.addEventListener("load", function(event) {
1865-
function findPremiumBanner() {
1866-
const title = document.querySelector(".article-page-header");
1867-
if (!title) return null;
1868-
const elems = title.parentElement.querySelectorAll("a");
1869-
return [...elems].find(d => d.href.includes("ph-abo"))
1866+
function extractKeywords() {
1867+
return document.querySelector("h1").textContent;
18701868
}
18711869

1870+
const isPremium = () => {
1871+
const metaElement = document.querySelector('meta[name="ad:teaser"]');
1872+
if (metaElement) {
1873+
if (metaElement.content === 'true')
1874+
return true;
1875+
}
1876+
return false;
1877+
};
1878+
18721879
async function onLoad() {
1873-
const head = findPremiumBanner();
1874-
if (!head) return;
1875-
head.after(await ophirofoxEuropresseLink());
1880+
if (!isPremium()) return;
1881+
document.querySelector("h1").after(await ophirofoxEuropresseLink(extractKeywords()));
18761882
}
18771883

18781884
onLoad().catch(console.error);
@@ -1890,13 +1896,16 @@
18901896
font-family: "Karla",ff-karla,sans-serif;
18911897
font-weight: 700;
18921898
text-align: center;
1893-
margin-bottom: 2rem!important;
1894-
1899+
display: block;
1900+
width: 200px;
1901+
margin-top: 1rem;
1902+
margin-bottom: 1rem;
1903+
18951904
}
18961905
18971906
.ophirofox-europresse:hover, .ophirofox-europresse:active {
1898-
background-color: #000000;
1899-
color: #ffffff;
1907+
background-color: #000000;
1908+
color: #ffffff;
19001909
}
19011910
`);
19021911
}

0 commit comments

Comments
 (0)