Skip to content

Commit

Permalink
BNF only : accès à mediapart via bnf (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremieGiffard authored Jan 30, 2025
1 parent a77de67 commit 02669b2
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 0 deletions.
48 changes: 48 additions & 0 deletions ophirofox/content_scripts/mediapart.js
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);
10 changes: 10 additions & 0 deletions ophirofox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,15 @@
"content_scripts/lavdn.css"
]
},
{
"matches": [
"https://www.mediapart.fr/*"
],
"js": [
"content_scripts/config.js",
"content_scripts/mediapart.js"
]
},
{
"matches": [
"https://www.ouest-france.fr/*"
Expand Down Expand Up @@ -712,6 +721,7 @@
"name": "BNF",
"AUTH_URL": "https://bnf.idm.oclc.org/login?url=https://nouveau.europresse.com/access/ip/default.aspx?un=D000067U_1",
"AUTH_URL_ARRETSURIMAGES" : "www-arretsurimages-net.bnf.idm.oclc.org",
"AUTH_URL_MEDIAPART": "https://bnf.idm.oclc.org/login?url=http://www.mediapart.fr/licence",
"AUTH_URL_PRESSREADER" : "www-pressreader-com.bnf.idm.oclc.org"
},
{
Expand Down

0 comments on commit 02669b2

Please sign in to comment.