-
-
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.
BNF only : accès à mediapart via bnf (#284)
- Loading branch information
1 parent
a77de67
commit 02669b2
Showing
2 changed files
with
58 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
|
||
/** | ||
* @description create link <a> to BNF mirror | ||
* @param {string} AUTH_URL_MEDIAPART | ||
*/ | ||
async function createLink(AUTH_URL_MEDIAPART) { | ||
const span = document.createElement("span"); | ||
span.textContent = "Lire avec BNF"; | ||
|
||
const a = document.createElement("a"); | ||
a.href = new URL(AUTH_URL_MEDIAPART); | ||
a.appendChild(span); | ||
|
||
return a; | ||
} | ||
|
||
/** | ||
* @description check DOM for article under paywall | ||
* @return {HTMLElement} DOM Premium Banner and head of the article | ||
*/ | ||
function findPremiumBanner() { | ||
const article = document.querySelector(".news__body__center__container"); | ||
if (!article) return null; | ||
const elems = article.querySelectorAll(".paywall-message"); | ||
console.log("elements",elems) | ||
//labels not the same for mobile or PC display | ||
const textToFind = ["réservée aux abonné·es", "réservé aux abonné·es"] | ||
|
||
return [...elems].filter((balise) => textToFind.some((text) => balise.textContent.toLowerCase().includes(text)) ) | ||
|
||
} | ||
|
||
/**@description check for BNF users. If yes, create link button */ | ||
async function onLoad() { | ||
|
||
const config = await configurationsSpecifiques(['BNF']) | ||
if(!config) return; | ||
const reserve = findPremiumBanner(); | ||
if (!reserve) return; | ||
|
||
for (const balise of reserve) { | ||
balise.appendChild(await createLink(config.AUTH_URL_MEDIAPART)) | ||
} | ||
} | ||
|
||
setTimeout(function(){ | ||
onLoad().catch(console.error); | ||
}, 1000); |
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