Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BNF only : arret sur images #283

Merged
merged 3 commits into from
Jan 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions ophirofox/content_scripts/arret-sur-images.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.ophirofox-europresse {
background-color: #f05246;
border: 1px #f05246 solid;
padding: calc(0.25em - 1px) 0.5em !important;
color: #fff;
font-family: "Merriweather", serif;
font-weight: 900 !important;
font-style: italic !important;
text-transform: none !important;
}
52 changes: 52 additions & 0 deletions ophirofox/content_scripts/arret-sur-images.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
//Aknowledgment : arret-sur-images feature found already mostly done on https://github.com/Rohirrim03/ profile.
//BNF : Bibliothèque Nationale de France

/**
* @description create link <a> to BNF mirror
* @param {string} AUTH_URL_ARRETSURIMAGES
*/
async function createLink(AUTH_URL_ARRETSURIMAGES) {
const span = document.createElement("span");
span.textContent = "Lire avec BNF";
span.className = "sub-stamp-component etiquette ophirofox-europresse";

const a = document.createElement("a");
var newUrl = new URL(window.location);//current page
newUrl.host = AUTH_URL_ARRETSURIMAGES //change only the domain name
newUrl.href
a.href = newUrl;

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(".article");
if (!article) return null;
const elems = article.querySelectorAll("span, mark");
const textToFind = ["réservé aux abonné.e.s", "Réservé à nos abonné.e.s"];

return [...elems].filter(d => textToFind.some(text => d.textContent.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.parentElement.appendChild(await createLink(config.AUTH_URL_ARRETSURIMAGES));
}
}

setTimeout(function(){
onLoad().catch(console.error);
}, 1000);
10 changes: 10 additions & 0 deletions ophirofox/content_scripts/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,16 @@ async function ophirofoxAskPermissions(partner_name) {
if (!granted) throw new Error("Permission not granted");
}

/**
* @description check if user plugin config match website specific config
* @param {string[]} configNames names of partners in manifest.js
* @return {{AUTH_URL:string, name:string,AUTH_URL_NAMEOFWEBSITE:string}} current config with specific property as defined in manifest.js
*/
async function configurationsSpecifiques(configNames){
const config = await ophirofox_config;
if (configNames.find((name) => name === config.name)) return config
}

const missing_permissions = [];

// Returns a list of permissions that must be asked for.
Expand Down
15 changes: 14 additions & 1 deletion ophirofox/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,18 @@
"css": [
"content_scripts/challenges.css"
]
},
{
"matches": [
"https://www.arretsurimages.net/*"
],
"js": [
"content_scripts/config.js",
"content_scripts/arret-sur-images.js"
],
"css": [
"content_scripts/arret-sur-images.css"
]
}
],
"browser_specific_settings": {
Expand Down Expand Up @@ -685,7 +697,8 @@
},
{
"name": "BNF",
"AUTH_URL": "https://bnf.idm.oclc.org/login?url=https://nouveau.europresse.com/access/ip/default.aspx?un=D000067U_1"
"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"
},
{
"name": "Bibliothèque Publique d'Information (BPI)",
Expand Down