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

Ajout des Échos #190

Merged
merged 5 commits into from
Jan 23, 2024
Merged

Ajout des Échos #190

merged 5 commits into from
Jan 23, 2024

Conversation

lbaudin
Copy link
Contributor

@lbaudin lbaudin commented Jan 23, 2024

No description provided.

Comment on lines 1 to 16
function extractKeywords() {
return extractKeywordsFromTitle() || extractKeywordsFromUrl(window.location);
}

function extractKeywordsFromTitle() {
const titleElem = document.querySelector("h1").childNodes[0];
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];*/
throw new Error("not implemented");
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vous pouvez enlever extractKeywordsFromUrl du coup


async function onLoad() {
/* Weird reloading after load */
await new Promise(r => setTimeout(r, 1000));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Le 1000 semble un peu aléatoire, non ? Il ne faudrait pas un mutationObserver ici, pour être sûr que l'on a bien l'élément que l'on attend ?

Comment on lines 27 to 28
const article = document.querySelectorAll("article")[0];
const elt = article.children[1].children[1].children[0].children[0].children[1].children[0]
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ça semble très très fragile, comme ça... On ne peut pas trouver un sélecteur plus précis?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pas vraiment, toutes les classes sont obfusquées, de type "sc-kla0ai-1". Après un rechargement de la page elles semblent être toujours identiques mais je pense qu'elles peuvent changer n'importe quand. Une alternative serait de mettre le lien directement dans le titre, au moins il n'y a qu'un seul h1.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Est-ce que l'on peut faire un query selector qui contient les tags des éléments, au moins?

Quelque chose comme article div[some_attr*=some_value] span

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

En fait j'avais déplacé le bouton pour le mettre à côté des boutons "Commenter", "Partager", etc, ce qui donne :

document.querySelector("button[aria-label=Commenter]")?.parentElement?.parentElement

ce qui me semble plus robuste.

On regarde 3 événements différents :
- changement dans <title> (nouvelle sous-page via un routeur javascript)
- changement dans <main> (fin du chargement de la sous-page)
- apparition d'une iframe (fin du chargement de la page initiale)
@lbaudin
Copy link
Contributor Author

lbaudin commented Jan 23, 2024

Nouveau commit avec des changements dans la logique de détection du chargement initial avec un mutationobserver.

@lbaudin lbaudin requested a review from lovasoa January 23, 2024 15:29
@lovasoa lovasoa merged commit 082e63d into lovasoa:master Jan 23, 2024
@lovasoa
Copy link
Owner

lovasoa commented Jan 23, 2024

Super, c'est intégré, merci pour votre contribution !

@Write Write mentioned this pull request Jan 26, 2024
Altonss added a commit to Altonss/ophirofox that referenced this pull request Apr 5, 2024
Support for it had been added in lovasoa#190.
@Altonss Altonss mentioned this pull request Apr 5, 2024
lovasoa pushed a commit that referenced this pull request Apr 6, 2024
Support for it had been added in #190.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants