|
1 | 1 | // ==UserScript== |
2 | | -// @version 2.6.10403.1420 |
| 2 | +// @version 2.6.10403.1738 |
3 | 3 | // @author Write |
4 | 4 | // @name OphirofoxScript |
5 | 5 | // @grant GM.getValue |
|
1597 | 1597 |
|
1598 | 1598 | window.addEventListener("load", function(event) { |
1599 | 1599 | function extractKeywords() { |
1600 | | - return document.querySelector("h1").textContent; |
| 1600 | + return document.querySelector("h1")?.textContent; |
1601 | 1601 | } |
1602 | 1602 |
|
1603 | | - async function createLink() { |
1604 | | - const span = document.createElement("span"); |
1605 | | - span.textContent = "Lire sur Europresse"; |
1606 | | - span.className = "premium-message ophirofox-europresse"; |
1607 | | - |
| 1603 | + async function injectButton() { |
| 1604 | + if (document.querySelector('.ophirofox-europresse')) return; |
| 1605 | + const reserved = document.querySelector(".typo-p2-paragraph p"); |
| 1606 | + if (!reserved || reserved.textContent.trim() !== "Article réservé aux abonnés") return; |
1608 | 1607 | const a = await ophirofoxEuropresseLink(extractKeywords()); |
1609 | | - a.classList.add("btn", "btn--premium"); |
1610 | | - a.innerHTML = ""; |
1611 | | - a.appendChild(span); |
1612 | | - |
1613 | | - return a; |
| 1608 | + a.classList.add("ophirofox-europresse", "btn", "relative", "btn-outline", "btn-primary", "btn-sm", "typo-caption-important", "self-start", "px-4", "py-1"); |
| 1609 | + reserved.closest(".typo-p2-paragraph").after(a); |
1614 | 1610 | } |
1615 | 1611 |
|
1616 | | - async function onLoad() { |
1617 | | - const reserve = document.querySelector(".premium-message"); |
1618 | | - if (!reserve) return; |
1619 | | - |
1620 | | - reserve.parentElement.appendChild(await createLink()); |
1621 | | - } |
1622 | | - |
1623 | | - onLoad().catch(console.error); |
| 1612 | + const observer = new MutationObserver(() => injectButton().catch(console.error)); |
| 1613 | + observer.observe(document.body, { |
| 1614 | + childList: true, |
| 1615 | + subtree: true |
| 1616 | + }); |
| 1617 | + injectButton().catch(console.error); |
1624 | 1618 | }); |
1625 | 1619 |
|
1626 | 1620 | pasteStyle(` |
|
2306 | 2300 | } |
2307 | 2301 |
|
2308 | 2302 | async function onLoad() { |
2309 | | - const head = document.querySelector(".article-premium-header"); |
| 2303 | + const head = document.querySelector(".badge-premium"); |
2310 | 2304 | if (!head) return; |
2311 | 2305 | head.appendChild(await createLink()); |
2312 | 2306 | } |
|
2788 | 2782 | if (match(hostname, "https://www.latribune.fr/*")) { |
2789 | 2783 |
|
2790 | 2784 | window.addEventListener("load", function(event) { |
2791 | | - function extractKeywords() { |
2792 | | - return document.querySelector('h1').textContent; |
2793 | | - } |
2794 | | - |
2795 | | - async function createLink() { |
2796 | | - const a = await ophirofoxEuropresseLink(extractKeywords()); |
2797 | | - a.classList.add(); |
2798 | | - return a; |
| 2785 | + function injectButton() { |
| 2786 | + const banner = document.querySelector('.bg-premium-10'); |
| 2787 | + if (!banner) return; |
| 2788 | + if (banner.querySelector('.ophirofox-europresse')) return; |
| 2789 | + const premiumBanner = [...banner.querySelectorAll('p')] |
| 2790 | + .find(p => p.textContent === 'Ce contenu est réservé aux abonnés'); |
| 2791 | + if (!premiumBanner) return; |
| 2792 | + ophirofoxEuropresseLink(document.querySelector('h1')?.textContent) |
| 2793 | + .then(a => premiumBanner.after(a)); |
2799 | 2794 | } |
2800 | 2795 |
|
2801 | | - function findPremiumBanner() { |
2802 | | - const title = document.querySelector('.rev-premium-tag-article-lt__container'); |
2803 | | - if (!title) return null; |
2804 | | - const elems = title.querySelectorAll('p'); |
2805 | | - return [...elems].find((d) => d.textContent === 'Ce contenu est réservé aux abonnés'); |
2806 | | - } |
| 2796 | + function watchPage(callback) { |
| 2797 | + // Navigation SPA via History API |
| 2798 | + const origPush = history.pushState.bind(history); |
| 2799 | + const origReplace = history.replaceState.bind(history); |
| 2800 | + history.pushState = (...args) => { |
| 2801 | + origPush(...args); |
| 2802 | + callback(); |
| 2803 | + }; |
| 2804 | + history.replaceState = (...args) => { |
| 2805 | + origReplace(...args); |
| 2806 | + callback(); |
| 2807 | + }; |
| 2808 | + window.addEventListener('popstate', callback); |
2807 | 2809 |
|
2808 | | - async function onLoad() { |
2809 | | - const premiumBanner = findPremiumBanner(); |
2810 | | - if (!premiumBanner) return; |
2811 | | - premiumBanner.after(await createLink()); |
| 2810 | + // MutationObserver pour le rendu dynamique |
| 2811 | + const observer = new MutationObserver(callback); |
| 2812 | + observer.observe(document.body, { |
| 2813 | + childList: true, |
| 2814 | + subtree: true |
| 2815 | + }); |
2812 | 2816 | } |
2813 | 2817 |
|
2814 | | - onLoad().catch(console.error); |
| 2818 | + watchPage(() => injectButton()); |
| 2819 | + injectButton(); |
2815 | 2820 | }); |
2816 | 2821 |
|
2817 | 2822 | pasteStyle(` |
|
2877 | 2882 | } |
2878 | 2883 |
|
2879 | 2884 | function findPremiumBanner() { |
2880 | | - const title = document.querySelector('div.header-subscriber'); |
| 2885 | + const title = document.querySelector('.tag-premium'); |
2881 | 2886 | if (!title) return null; |
2882 | 2887 | return title; |
2883 | 2888 | } |
|
4036 | 4041 |
|
4037 | 4042 | window.addEventListener("load", function(event) { |
4038 | 4043 | function extractKeywords() { |
4039 | | - return document.querySelector(".editoSocialBar__item[data-title]").dataset.title |
| 4044 | + return document.querySelector("h1")?.textContent; |
4040 | 4045 | } |
4041 | | - |
4042 | 4046 | async function createLink() { |
4043 | 4047 | const a = await ophirofoxEuropresseLink(extractKeywords()); |
4044 | | - a.style = 'font-family: "arimo-bold",Arial,Helvetica,sans-serif; border-bottom: 2px solid #000; margin-left : 1rem' |
| 4048 | + a.style.cssText = ` |
| 4049 | + font-family: "arimo-bold",Arial,Helvetica,sans-serif; |
| 4050 | + border-bottom: 2px solid #000; |
| 4051 | + float: right; |
| 4052 | + margin-left: 10px; |
| 4053 | +
|
| 4054 | + font-weight: 600; |
| 4055 | + `; |
4045 | 4056 | return a; |
4046 | 4057 | } |
4047 | 4058 |
|
4048 | 4059 | function findPremiumBanner() { |
4049 | | - const div = document.querySelector(".epPayWallTop"); |
| 4060 | + const div = document.querySelector(".c-paywall-label"); |
4050 | 4061 | if (!div) return null; |
4051 | | - console.log('all div', div) |
4052 | | - console.log('last child', div.lastElementChild) |
4053 | | - return elem = div.lastElementChild; |
| 4062 | + return div.lastElementChild; |
4054 | 4063 | } |
4055 | | - |
4056 | 4064 | async function onLoad() { |
4057 | 4065 | const premiumBanner = findPremiumBanner(); |
4058 | 4066 | if (!premiumBanner) return; |
4059 | 4067 | premiumBanner.after(await createLink()); |
4060 | 4068 | } |
4061 | | - |
4062 | 4069 | onLoad().catch(console.error); |
4063 | 4070 | }); |
4064 | 4071 |
|
|
0 commit comments