Skip to content

Commit 1bb93a7

Browse files
Fix/mediapart bnf (#369)
1 parent 3e1b3ca commit 1bb93a7

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

ophirofox/content_scripts/mediapart.js

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ async function createLink(AUTH_URL_MEDIAPART, name) {
88
span.textContent = "Lire avec " + name;
99

1010
const a = document.createElement("a");
11-
a.href = new URL(window.location);
12-
a.host = AUTH_URL_MEDIAPART;
11+
a.href = new URL(
12+
"licence",
13+
"https://" + AUTH_URL_MEDIAPART
14+
);
1315
a.appendChild(span);
1416
return a;
1517
}
@@ -33,26 +35,35 @@ function findPremiumBanner() {
3335
/**
3436
* @description if not properly logged on the mirror website, fetch the login page
3537
*/
36-
function handleMediapartMirror(config) {
38+
async function handleMediapartMirror(config) {
3739
const navBar = document.querySelector("ul.nav__actions");
3840
const spans = navBar.querySelectorAll("span");
3941

4042
let isNotConnected = Array.from(spans).find(
4143
(elem) => elem.textContent == "Se connecter"
4244
);
45+
46+
let articlePath ='';
47+
await chrome.storage.sync.get(['ophirofox_mediapart_article']).then((result) => {
48+
articlePath = result.ophirofox_mediapart_article
49+
})
50+
51+
let currentPage = new URL(window.location)
4352
if (isNotConnected) {
44-
//account name not found. fetch login page
45-
const LOGIN_PAGE = new URL(
46-
"licence",
47-
"https://" + config.AUTH_URL_MEDIAPART
48-
);
49-
fetch(LOGIN_PAGE).then(() => window.location.reload());
53+
console.error("ophirofox login failed")
54+
return
55+
}else if(currentPage.pathname != articlePath){
56+
//redirect to mirror article
57+
window.location.pathname = articlePath
5058
}
5159
}
5260

5361
async function handleMediapart(config) {
5462
const reserve = findPremiumBanner();
5563
if (!reserve) return;
64+
chrome.storage.sync.set({
65+
"ophirofox_mediapart_article": new URL(window.location).pathname
66+
})
5667

5768
for (const balise of reserve) {
5869
balise.appendChild(await createLink(config.AUTH_URL_MEDIAPART, config.name));

0 commit comments

Comments
 (0)