Skip to content

Commit

Permalink
Amélioration du choix des mots de recherche et du bouton sur lefigaro
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Sep 21, 2020
1 parent 26f3caa commit c6fa4f7
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ d'être redirigé automatiquement vers une page de recherche europresse qui cont

## Sites supportés
- [Le Monde](https://www.lemonde.fr/)
- [Le Figaro](https://www.lefigaro.fr/)
- [Libération](https://www.liberation.fr/)

Vous pouvez proposer d'autres sites en ouvrant une [demande sur github](https://github.com/lovasoa/ophirofox/issues)
Expand Down
8 changes: 7 additions & 1 deletion ophirofox/content_scripts/europresse_search.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@ function onLoad() {
const url = new URL(window.location);
const search_terms = url.searchParams.get("ophirofox_keywords");
if (!search_terms) return;
const stopwords = new Set(['d', 'l', 'et']);
const keywords = search_terms
.replace(/œ/g, 'oe')
.split(/[^\p{L}]+/u)
.filter(w => !stopwords.has(w))
.join(' ');
const keyword_field = document.getElementById("Keywords");
keyword_field.value = search_terms;
keyword_field.value = keywords;
keyword_field.form.submit();
}

Expand Down
9 changes: 6 additions & 3 deletions ophirofox/content_scripts/lefigaro.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
.ophirofox-europresse {
color: black;
margin-left: 7px;
z-index: 10;
margin:0 8px;
padding:4px 16px;
display:block;
font-family:source-sans-pro,sans-serif;
background-color:#fff7E4;
color:#163860;
}
4 changes: 2 additions & 2 deletions ophirofox/content_scripts/lefigaro.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function makeEuropresseUrl(lemondeUrl) {
}

function extractKeywords() {
return document.querySelector("h1").textContent.split(/[^\w]+/).join(" ");
return document.querySelector("h1").textContent;
}

function createLink() {
Expand All @@ -22,7 +22,7 @@ function createLink() {
function findPremiumBanner() {
const title = document.querySelector("h1");
if (!title) return null;
const divs = title.parentElement.querySelectorAll("div");
const divs = title.parentElement.querySelectorAll("div>div");
return [...divs].find(d => d.textContent.includes("Réservé aux abonnés"))
}

Expand Down
8 changes: 3 additions & 5 deletions ophirofox/content_scripts/lemonde.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,19 @@ function makeEuropresseUrl(lemondeUrl) {
}

function extractKeywords() {
const stopwords = new Set(['d', 'l', 'et'])
const keywords = extractKeywordsFromTitle() || extractKeywordsFromUrl(window.location);
return keywords.filter(w => !stopwords.has(w)).join(' ');
return extractKeywordsFromTitle() || extractKeywordsFromUrl(window.location);
}

function extractKeywordsFromTitle() {
const titleElem = document.querySelector("h1.article__title");
return titleElem && titleElem.textContent.split(/[^\w]+/);
return titleElem && titleElem.textContent;
}

function extractKeywordsFromUrl(url) {
const source_url = new URL(url);
const lemonde_match = source_url.pathname.match(/([^/.]+)(_\d*_\d*\.html)?$/);
if (!lemonde_match) throw new Error("Could not find keywords in lemonde url");
return lemonde_match[1].split('-');
return lemonde_match[1];
}

function createLink() {
Expand Down
4 changes: 1 addition & 3 deletions ophirofox/content_scripts/liberation.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ function extractKeywordsFromUrl(url) {
const source_url = new URL(url);
const keywords_in_url = source_url.pathname.match(/([^/.]+)_\d*$/);
if (!keywords_in_url) throw new Error("Could not find keywords in url");
const stopwords = new Set(['d', 'l', 'et'])
const search_terms = keywords_in_url[1].split('-').filter(w => !stopwords.has(w));
return search_terms.join(" ");
return keywords_in_url[1];
}

function createLink() {
Expand Down

0 comments on commit c6fa4f7

Please sign in to comment.