|
1 | 1 | // ==UserScript== |
2 | | -// @version 2.5.250312.1859 |
| 2 | +// @version 2.5.250318.2132 |
3 | 3 | // @author Write |
4 | 4 | // @name OphirofoxScript |
5 | 5 | // @grant GM.getValue |
|
104 | 104 | // @include https://www.lemonde.fr/* |
105 | 105 | // @include https://www.liberation.fr/* |
106 | 106 | // @include https://next.liberation.fr/* |
107 | | -// @include https://www.lefigaro.fr/* |
108 | | -// @include https://leparticulier.lefigaro.fr/* |
| 107 | +// @include https://*.lefigaro.fr/* |
109 | 108 | // @include https://www.monde-diplomatique.fr/* |
110 | 109 | // @include https://www.courrierdesmaires.fr/* |
111 | 110 | // @include https://www.la-croix.com/* |
|
1233 | 1232 | `); |
1234 | 1233 | } |
1235 | 1234 |
|
1236 | | - if ("https://www.lefigaro.fr/*".includes(hostname)) { |
1237 | | - |
1238 | | - window.addEventListener("load", function(event) { |
1239 | | - function extractKeywords() { |
1240 | | - return document.querySelector("h1").textContent; |
1241 | | - } |
1242 | | - |
1243 | | - async function createLink() { |
1244 | | - const a = await ophirofoxEuropresseLink(extractKeywords()); |
1245 | | - a.classList.add("fig-premium-mark-article__text"); |
1246 | | - return a; |
1247 | | - } |
1248 | | - |
1249 | | - |
1250 | | - function findPremiumBanner() { |
1251 | | - const title = document.querySelector("h1"); |
1252 | | - if (!title) return null; |
1253 | | - const elems = title.parentElement.querySelectorAll("span"); |
1254 | | - return [...elems].find(d => d.textContent.includes("Réservé aux abonnés")) |
1255 | | - } |
1256 | | - |
1257 | | - async function onLoad() { |
1258 | | - const premiumBanner = findPremiumBanner(); |
1259 | | - if (!premiumBanner) return; |
1260 | | - premiumBanner.after(await createLink()); |
1261 | | - } |
1262 | | - |
1263 | | - onLoad().catch(console.error); |
1264 | | - }); |
1265 | | - |
1266 | | - pasteStyle(` |
1267 | | - .ophirofox-europresse { |
1268 | | - margin-left: 10px; |
1269 | | - } |
1270 | | - `); |
1271 | | - } |
1272 | | - |
1273 | | - if ("https://leparticulier.lefigaro.fr/*".includes(hostname)) { |
| 1235 | + if ("https://*.lefigaro.fr/*".includes(hostname)) { |
1274 | 1236 |
|
1275 | 1237 | window.addEventListener("load", function(event) { |
1276 | 1238 | function extractKeywords() { |
|
1304 | 1266 | .ophirofox-europresse { |
1305 | 1267 | margin-left: 10px; |
1306 | 1268 | } |
| 1269 | + |
| 1270 | + .appconsent_noscroll { |
| 1271 | + overflow: unset !important; |
| 1272 | + } |
1307 | 1273 | `); |
1308 | 1274 | } |
1309 | 1275 |
|
|
1347 | 1313 | .ophirofox-europresse { |
1348 | 1314 | margin-left: 10px; |
1349 | 1315 | } |
| 1316 | + |
| 1317 | + .appconsent_noscroll { |
| 1318 | + overflow: unset !important; |
| 1319 | + } |
1350 | 1320 | `); |
1351 | 1321 | } |
1352 | 1322 |
|
|
3532 | 3502 | return await ophirofoxEuropresseLink(); |
3533 | 3503 | } |
3534 | 3504 |
|
| 3505 | + // Variable pour stocker l'observer |
| 3506 | + let observer = null; |
| 3507 | + |
| 3508 | + // Variable pour stocker le timer de surveillance post-injection |
| 3509 | + let checkTimer = null; |
| 3510 | + |
| 3511 | + // Variable pour suivre si un lien a déjà été ajouté sur l'URL actuelle |
| 3512 | + let linkAddedForCurrentUrl = false; |
| 3513 | + |
| 3514 | + // Fonction pour vérifier si le lien existe déjà |
| 3515 | + function linkExists() { |
| 3516 | + // Vérification plus précise - s'assurer qu'on cherche le bon élément |
| 3517 | + const existingLink = document.querySelector('.ophirofox-link'); |
| 3518 | + |
| 3519 | + // Ajouter un log pour déboguer |
| 3520 | + // console.log('Checking if link exists:', existingLink ? 'YES' : 'NO'); |
| 3521 | + |
| 3522 | + return !!existingLink; |
| 3523 | + } |
| 3524 | + |
| 3525 | + // Fonction pour injecter le lien |
| 3526 | + async function injectLink() { |
| 3527 | + // Vérification plus stricte - ne pas injecter si le lien existe déjà |
| 3528 | + if (linkExists()) { |
| 3529 | + // console.log('Link already exists, skipping injection'); |
| 3530 | + return false; |
| 3531 | + } |
| 3532 | + |
| 3533 | + const premiumDiv = document.querySelector("div.views-article__premium"); |
| 3534 | + if (premiumDiv) { |
| 3535 | + const link = await createLink(); |
| 3536 | + |
| 3537 | + // S'assurer que la classe est bien définie |
| 3538 | + if (!link.classList.contains('ophirofox-link')) { |
| 3539 | + link.classList.add('ophirofox-link'); |
| 3540 | + } |
| 3541 | + |
| 3542 | + premiumDiv.before(link); |
| 3543 | + |
| 3544 | + return true; |
| 3545 | + } |
| 3546 | + return false; |
| 3547 | + } |
| 3548 | + |
| 3549 | + // Fonction pour surveiller si le lien est supprimé après injection |
| 3550 | + function monitorLinkPresence() { |
| 3551 | + // Annuler le timer précédent s'il existe |
| 3552 | + if (checkTimer) { |
| 3553 | + clearInterval(checkTimer); |
| 3554 | + } |
| 3555 | + |
| 3556 | + // Vérifier toutes les 500ms pendant 5 secondes si le lien existe toujours |
| 3557 | + let checkCount = 0; |
| 3558 | + checkTimer = setInterval(async () => { |
| 3559 | + checkCount++; |
| 3560 | + |
| 3561 | + // Vérifier explicitement si le lien existe |
| 3562 | + const linkPresent = linkExists(); |
| 3563 | + |
| 3564 | + // Si le lien n'existe pas mais qu'il a été ajouté précédemment, essayer de le réinjecter |
| 3565 | + if (!linkPresent && linkAddedForCurrentUrl) { |
| 3566 | + console.log('Link was removed, reinserting...'); |
| 3567 | + await injectLink(); |
| 3568 | + } |
| 3569 | + |
| 3570 | + // Arrêter la vérification après 5 secondes (10 vérifications) |
| 3571 | + if (checkCount >= 10) { |
| 3572 | + clearInterval(checkTimer); |
| 3573 | + checkTimer = null; |
| 3574 | + } |
| 3575 | + }, 500); |
| 3576 | + } |
| 3577 | + |
| 3578 | + function startObserver() { |
| 3579 | + // Nettoyer l'ancien observer s'il existe |
| 3580 | + if (observer) { |
| 3581 | + observer.disconnect(); |
| 3582 | + } |
| 3583 | + |
| 3584 | + // Créer un nouvel observer |
| 3585 | + observer = new MutationObserver(async (mutations, obs) => { |
| 3586 | + // Vérifier d'abord si le lien existe déjà |
| 3587 | + if (linkExists()) { |
| 3588 | + linkAddedForCurrentUrl = true; // Mettre à jour l'état |
| 3589 | + return; // Ne rien faire si le lien existe déjà |
| 3590 | + } |
| 3591 | + |
| 3592 | + // Si le lien n'a pas encore été ajouté pour cette URL |
| 3593 | + if (!linkAddedForCurrentUrl) { |
| 3594 | + const premiumDiv = document.querySelector("div.views-article__premium"); |
| 3595 | + if (premiumDiv) { |
| 3596 | + const injected = await injectLink(); |
| 3597 | + if (injected) { |
| 3598 | + // Marquer que le lien a été ajouté pour cette URL |
| 3599 | + linkAddedForCurrentUrl = true; |
| 3600 | + // Démarrer la surveillance post-injection |
| 3601 | + monitorLinkPresence(); |
| 3602 | + } |
| 3603 | + } |
| 3604 | + } |
| 3605 | + }); |
| 3606 | + |
| 3607 | + // Démarrer l'observation |
| 3608 | + observer.observe(document.body, { |
| 3609 | + childList: true, |
| 3610 | + subtree: true |
| 3611 | + }); |
| 3612 | + } |
| 3613 | + |
| 3614 | + function watchUrlChanges() { |
| 3615 | + // Stocker l'URL actuelle |
| 3616 | + let currentUrl = window.location.href; |
| 3617 | + |
| 3618 | + // Surveiller les changements d'URL |
| 3619 | + setInterval(() => { |
| 3620 | + if (currentUrl !== window.location.href) { |
| 3621 | + // console.log('URL changed: ', window.location.href); |
| 3622 | + currentUrl = window.location.href; |
| 3623 | + |
| 3624 | + // Arrêter la surveillance post-injection |
| 3625 | + if (checkTimer) { |
| 3626 | + clearInterval(checkTimer); |
| 3627 | + checkTimer = null; |
| 3628 | + } |
| 3629 | + |
| 3630 | + // Réinitialiser le statut pour la nouvelle URL |
| 3631 | + linkAddedForCurrentUrl = false; |
| 3632 | + |
| 3633 | + // Relancer l'observer quand l'URL change |
| 3634 | + startObserver(); |
| 3635 | + } |
| 3636 | + }, 500); // Vérifier toutes les 500ms |
| 3637 | + } |
| 3638 | + |
3535 | 3639 | async function onLoad() { |
3536 | | - const statusElem = document.querySelector("span.article-abo-tag"); |
3537 | | - if (!statusElem) return; |
3538 | | - statusElem.before(await createLink()); |
| 3640 | + // Démarrer l'observer initial |
| 3641 | + startObserver(); |
| 3642 | + |
| 3643 | + // Configurer la surveillance des changements d'URL |
| 3644 | + watchUrlChanges(); |
3539 | 3645 | } |
3540 | 3646 |
|
| 3647 | + // Lancer la fonction principale avec gestion d'erreur |
3541 | 3648 | onLoad().catch(console.error); |
3542 | 3649 | }); |
3543 | 3650 |
|
3544 | 3651 | pasteStyle(` |
3545 | 3652 | .ophirofox-europresse { |
3546 | | - background-color: #fcc525; |
3547 | | - font-family: "DIN",Helvetica,arial,sans-serif; |
3548 | | - color: #101010 !important; |
| 3653 | + --tw-bg-opacity: 1; |
| 3654 | + background-color: #ffdc27; |
| 3655 | + background-color: rgb(255 220 39 / var(--tw-bg-opacity, 1)); |
| 3656 | + font-family: IBM Plex Sans Condensed; |
| 3657 | + font-size: .875rem; |
| 3658 | + line-height: 1.25rem; |
3549 | 3659 | text-transform: uppercase; |
3550 | | - font-size: 11px; |
3551 | | - padding: 4px 6px 1px 6px; |
3552 | | - display: inline-block; |
| 3660 | + --tw-text-opacity: 1; |
| 3661 | + color: #000; |
| 3662 | + color: rgb(0 0 0 / var(--tw-text-opacity, 1)); |
| 3663 | + font-weight: 700; |
| 3664 | + width: 200px; |
| 3665 | + margin-left: 30px; |
| 3666 | + padding: 10px; |
3553 | 3667 | } |
3554 | 3668 | |
3555 | 3669 | .ophirofox-europresse:hover { |
3556 | | - color: #a6a6a6 !important; |
| 3670 | + --tw-bg-opacity: 1; |
| 3671 | + background-color: #ffe458; |
| 3672 | + background-color: rgb(255 228 88 / var(--tw-bg-opacity, 1)); |
3557 | 3673 | } |
3558 | 3674 | `); |
3559 | 3675 | } |
|
0 commit comments