-
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout El-Pais pour le pack optionnel Lexis Nexis (#303)
* Ajout El-Pais pour le pack optionnel Lexis Nexis * Ajout El-Pais pour le pack optionnel Lexis Nexis
- Loading branch information
1 parent
7133d0a
commit f6e541c
Showing
4 changed files
with
71 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters