Skip to content

Commit

Permalink
Ajout El-Pais pour le pack optionnel Lexis Nexis (#303)
Browse files Browse the repository at this point in the history
* Ajout El-Pais pour le pack optionnel Lexis Nexis

* Ajout El-Pais pour le pack optionnel Lexis Nexis
  • Loading branch information
JeremieGiffard authored Feb 25, 2025
1 parent 7133d0a commit f6e541c
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ Voici la liste triée par ordre alphabétique :
- [Courrier international](https://www.courrierinternational.com)
- [De Morgen (Belgique - néerlandophone)](https://www.demorgen.be/)
- [De Standaard (Belgique - néerlandophone)](https://www.standaard.be/)
- [El Pais (Espagne - nécessite le pack europress Lexis Nexis)](https://www.standaard.be/)
- [Financial Times (Royaume-Uni)](https://www.ft.com/)
- [Gazet van Antwerpen (Belgique - néerlandophone)](https://www.gva.be/)
- [Het Laatste Nieuws (Belgique - néerlandophone)](https://www.hln.be/)
Expand Down
8 changes: 8 additions & 0 deletions ophirofox/content_scripts/el-pais.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.ophirofox-europresse {
padding: .5rem;
font-size: .75rem;
min-width: 10rem;
background: #f7cf3c;
font-weight: 700;
font-family: MarcinAntB,sans-serif;
}
50 changes: 50 additions & 0 deletions ophirofox/content_scripts/el-pais.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
let buttonAdded = false;
function extractKeywords() {
let currentURL = new URL(window.location);
// get title at the end of URL pathname.
// Remove noise characters, and make it search-ready for europress
const result = currentURL.pathname
.split("/")
.pop()
.replace(/-|\.html$/g, " ")
.trim();
return result;
}

async function createLink(title) {
if (title && buttonAdded == false) {
const div = document.createElement("div");
const a = await ophirofoxEuropresseLink(extractKeywords());
a.textContent = "Lire sur europresse (Lexis Nexis)";
div.appendChild(a);
title.after(div);
}
}

async function onLoad() {
console.log("ophirofox loaded");
const callback = (mutationList, observer) => {
for (const mutation of mutationList) {
if (mutation.type === "childList") {
for (let node of mutation.addedNodes) {
const paywall = document.querySelector("#ctn_freemium_article");
if (paywall == null) return;

if (buttonAdded == false) {
const article = document.querySelector(".a_s_b");
createLink(article);

const title = document.querySelector("h1");
createLink(title);
}
buttonAdded = true;
observer.disconnect();
}
}
}
};
const htmlElement = document.querySelector("article");
const observer = new MutationObserver(callback);
observer.observe(htmlElement, { childList: true, subtree: true });
}
onLoad().catch(console.error);
12 changes: 12 additions & 0 deletions ophirofox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,18 @@
"content_scripts/config.js",
"content_scripts/usineNouvelle.js"
]
},
{
"matches": [
"https://elpais.com/*"
],
"js": [
"content_scripts/config.js",
"content_scripts/el-pais.js"
],
"css":[
"content_scripts/el-pais.css"
]
}
],
"browser_specific_settings": {
Expand Down

0 comments on commit f6e541c

Please sign in to comment.