-
-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Ajout du support pour Le Progrès (#206)
* Ajout d'un fichier CONTRIBUTING.md * Support du site Le Progrès - leprogres.fr * fix: Le Progrès, selector pour le titre * Le Progrès : privilégier la recherche de mots clés sur l'URL * Le Progrès : ajout dans le README
- Loading branch information
Showing
5 changed files
with
128 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,51 @@ | ||
# Essayer l'extension dans Firefox | ||
|
||
Pour essayer l'extension en cours de développement, suivre ce guide : | ||
|
||
https://developer.mozilla.org/fr/docs/Mozilla/Add-ons/WebExtensions/Your_first_WebExtension#essai | ||
|
||
# Ajout du support d'un site de presse | ||
|
||
- Dans le fichier `ophirofox/manifest.json`, ajouter une nouvelle entrée dans le tableau `content_scripts`. | ||
|
||
```json | ||
{ | ||
"matches": [ | ||
"https://www.mon-nouveau-site-de-presse.fr/*" | ||
], | ||
"js": [ | ||
"content_scripts/config.js", | ||
"content_scripts/mon-nouveau-site-de-presse.js" | ||
], | ||
"css": [ | ||
"content_scripts/mon-nouveau-site-de-presse.css" | ||
] | ||
}, | ||
``` | ||
- Créer les fichiers js et css correspondant, dans le répertoire `ophirofox/content_scripts` | ||
|
||
Vous pouvez par exemple copier-coller `ophirofox/content_scripts/lemonde.js` pour servir de base. | ||
|
||
- Trouver les mots clés du titre | ||
|
||
Dans la méthode `extractKeywordsFromTitle`, modifier le querySelector pour correspondre au titre de l'article | ||
|
||
- Trouver les mots clés dans l'url | ||
|
||
Tester la regex de la méthode `extractKeywordsFromUrl` pour récupérer les mots clés de l'URL, la modifier si besoin | ||
|
||
- Ajouter le bouton Lire sur Europress dans l'entête de l'article | ||
|
||
Dans la méthode `onLoad`, modifier le premier querySelector pour trouver la zone où ajouter le bouton, par exemple une div d'informations sous le titre | ||
|
||
- Ajouter un second bouton dans le paywall (fenêtre d'abonnement) | ||
|
||
S'il y a une fenêtre paywall qui s'affiche, essayer de récupérer le bouton d'abonnement avec un querySelector et ajouter un second lien Europress avant | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
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,5 @@ | ||
.ophirofox-europresse { | ||
margin-left: 4px; | ||
margin-top: 0px; | ||
|
||
} |
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,59 @@ | ||
function extractKeywords() { | ||
// Works better with keywords from url | ||
return extractKeywordsFromUrl(window.location) || extractKeywordsFromTitle(); | ||
} | ||
|
||
function extractKeywordsFromTitle() { | ||
const titleElem = document.querySelector("head > title, article h1"); | ||
return titleElem && titleElem.textContent; | ||
} | ||
|
||
function extractKeywordsFromUrl(url) { | ||
const source_url = new URL(url); | ||
const le_progres_match = source_url.pathname.match(/([^/.]+)(_\d*_\d*\.html)?$/); | ||
if (!le_progres_match) return false; | ||
return le_progres_match[1]; | ||
} | ||
|
||
async function createLink() { | ||
const a = await ophirofoxEuropresseLink(extractKeywords()); | ||
a.classList.add("btn", "bt_default"); | ||
return a; | ||
} | ||
|
||
function waitForElm(selector) { | ||
return new Promise(resolve => { | ||
if (document.querySelector(selector)) { | ||
return resolve(document.querySelector(selector)); | ||
} | ||
|
||
const observer = new MutationObserver(mutations => { | ||
if (document.querySelector(selector)) { | ||
observer.disconnect(); | ||
resolve(document.querySelector(selector)); | ||
} | ||
}); | ||
|
||
observer.observe(document.body, { | ||
childList: true, | ||
subtree: true | ||
}); | ||
}); | ||
} | ||
|
||
async function onLoad() { | ||
const actionElement = document.querySelector(".fullDetailActions"); | ||
if (actionElement) { | ||
actionElement.appendChild(await createLink()); | ||
} | ||
|
||
let paywallElem = await waitForElm(".p3-advanced-paywall"); | ||
if (!paywallElem) return; | ||
|
||
const link = await createLink(); | ||
link.className = "button"; | ||
paywallElem.parentNode.insertBefore(link, paywallElem); | ||
|
||
} | ||
|
||
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