Skip to content

Commit 98e0869

Browse files
[Backport mv3] Fix Nice Matin La Tribune SudOuest La Montagne Usine Nouvelle (#435)
Co-authored-by: Write <541722+Write@users.noreply.github.com>
1 parent 4e735bc commit 98e0869

File tree

5 files changed

+45
-51
lines changed

5 files changed

+45
-51
lines changed
Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,16 @@
11
function extractKeywords() {
2-
return document.querySelector("h1").textContent;
2+
return document.querySelector("h1")?.textContent;
33
}
44

5-
async function createLink() {
6-
const span = document.createElement("span");
7-
span.textContent = "Lire sur Europresse";
8-
span.className = "premium-message ophirofox-europresse";
9-
5+
async function injectButton() {
6+
if (document.querySelector('.ophirofox-europresse')) return;
7+
const reserved = document.querySelector(".typo-p2-paragraph p");
8+
if (!reserved || reserved.textContent.trim() !== "Article réservé aux abonnés") return;
109
const a = await ophirofoxEuropresseLink(extractKeywords());
11-
a.classList.add("btn", "btn--premium");
12-
a.innerHTML = "";
13-
a.appendChild(span);
14-
15-
return a;
16-
}
17-
18-
async function onLoad() {
19-
const reserve = document.querySelector(".premium-message");
20-
if (!reserve) return;
21-
22-
reserve.parentElement.appendChild(await createLink());
10+
a.classList.add("ophirofox-europresse", "btn", "relative", "btn-outline", "btn-primary", "btn-sm", "typo-caption-important", "self-start", "px-4", "py-1");
11+
reserved.closest(".typo-p2-paragraph").after(a);
2312
}
2413

25-
onLoad().catch(console.error);
14+
const observer = new MutationObserver(() => injectButton().catch(console.error));
15+
observer.observe(document.body, { childList: true, subtree: true });
16+
injectButton().catch(console.error);
Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
1-
function extractKeywords() {
2-
return document.querySelector('h1').textContent;
1+
function injectButton() {
2+
const banner = document.querySelector('.bg-premium-10');
3+
if (!banner) return;
4+
if (banner.querySelector('.ophirofox-europresse')) return;
5+
const premiumBanner = [...banner.querySelectorAll('p')]
6+
.find(p => p.textContent === 'Ce contenu est réservé aux abonnés');
7+
if (!premiumBanner) return;
8+
ophirofoxEuropresseLink(document.querySelector('h1')?.textContent)
9+
.then(a => premiumBanner.after(a));
310
}
411

5-
async function createLink() {
6-
const a = await ophirofoxEuropresseLink(extractKeywords());
7-
a.classList.add();
8-
return a;
9-
}
12+
function watchPage(callback) {
13+
// Navigation SPA via History API
14+
const origPush = history.pushState.bind(history);
15+
const origReplace = history.replaceState.bind(history);
16+
history.pushState = (...args) => { origPush(...args); callback(); };
17+
history.replaceState = (...args) => { origReplace(...args); callback(); };
18+
window.addEventListener('popstate', callback);
1019

11-
function findPremiumBanner() {
12-
const title = document.querySelector('.rev-premium-tag-article-lt__container');
13-
if (!title) return null;
14-
const elems = title.querySelectorAll('p');
15-
return [...elems].find((d) => d.textContent === 'Ce contenu est réservé aux abonnés');
16-
}
17-
18-
async function onLoad() {
19-
const premiumBanner = findPremiumBanner();
20-
if (!premiumBanner) return;
21-
premiumBanner.after(await createLink());
20+
// MutationObserver pour le rendu dynamique
21+
const observer = new MutationObserver(callback);
22+
observer.observe(document.body, { childList: true, subtree: true });
2223
}
2324

24-
onLoad().catch(console.error);
25+
watchPage(() => injectButton());
26+
injectButton();

ophirofox/content_scripts/nice-matin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ async function createLink() {
55
}
66

77
function findPremiumBanner() {
8-
const title = document.querySelector('div.header-subscriber');
8+
const title = document.querySelector('.tag-premium');
99
if (!title) return null;
1010
return title;
1111
}

ophirofox/content_scripts/sudouest.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ function findPremiumBanner() {
1717
}
1818

1919
async function onLoad() {
20-
const head = document.querySelector(".article-premium-header");
20+
const head = document.querySelector(".badge-premium");
2121
if (!head) return;
2222
head.appendChild(await createLink());
2323
}
Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
function extractKeywords() {
2-
return document.querySelector(".editoSocialBar__item[data-title]").dataset.title
2+
return document.querySelector("h1")?.textContent;
33
}
4-
54
async function createLink() {
65
const a = await ophirofoxEuropresseLink(extractKeywords());
7-
a.style = 'font-family: "arimo-bold",Arial,Helvetica,sans-serif; border-bottom: 2px solid #000; margin-left : 1rem'
6+
a.style.cssText = `
7+
font-family: "arimo-bold",Arial,Helvetica,sans-serif;
8+
border-bottom: 2px solid #000;
9+
float: right;
10+
margin-left: 10px;
11+
12+
font-weight: 600;
13+
`;
814
return a;
915
}
10-
1116
function findPremiumBanner() {
12-
const div = document.querySelector(".epPayWallTop");
17+
const div = document.querySelector(".c-paywall-label");
1318
if (!div) return null;
14-
console.log('all div', div)
15-
console.log('last child', div.lastElementChild)
16-
return elem = div.lastElementChild;
19+
return div.lastElementChild;
1720
}
18-
1921
async function onLoad() {
2022
const premiumBanner = findPremiumBanner();
2123
if (!premiumBanner) return;
2224
premiumBanner.after(await createLink());
2325
}
24-
25-
onLoad().catch(console.error);
26+
onLoad().catch(console.error);

0 commit comments

Comments
 (0)