54 lines
2.0 KiB
JavaScript
54 lines
2.0 KiB
JavaScript
// search bar to send a request to a search engine for the current domain when sent
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
// Obtient le nom de domaine de la page courante
|
|
const currentDomain = window.location.hostname;
|
|
const form = document.getElementById('recherche');
|
|
|
|
// Ajoute un écouteur d'événement pour l'événement 'submit'
|
|
form.addEventListener('submit', function (event) {
|
|
// Empêche le comportement par défaut du formulaire
|
|
event.preventDefault()
|
|
const query = document.getElementById('query').value
|
|
const url = `https://duckduckgo.com/?q=${encodeURIComponent(query)}+site%3A${encodeURIComponent(currentDomain)}`;
|
|
|
|
window.location.href = url;
|
|
});
|
|
|
|
// navigation au clavier
|
|
// Sélectionnez le lien à cliquer
|
|
const nextArticleLink = document.querySelector('a.next-article');
|
|
const previousArticleLink = document.querySelector('a.previous-article');
|
|
|
|
// Ajoutez un événement de clic au lien
|
|
nextArticleLink.addEventListener('click', function () {
|
|
// Redirigez l'utilisateur vers la page suivante
|
|
window.location.href = nextArticleLink.href;
|
|
});
|
|
previousArticleLink.addEventListener('click', function () {
|
|
// Redirigez l'utilisateur vers la page suivante
|
|
window.location.href = nextArticleLink.href;
|
|
});
|
|
|
|
|
|
|
|
// Ajoutez un événement de touche au document
|
|
document.addEventListener('keydown', function (event) {
|
|
// Vérifiez si la touche appuyée est 'n' ou la flèche droite
|
|
if (event.key === 'n' || event.key === 'ArrowRight') {
|
|
// Empêche le comportement par défaut de la touche
|
|
event.preventDefault();
|
|
|
|
// Cliquez sur le lien
|
|
nextArticleLink.click();
|
|
}
|
|
if (event.key === 'p' || event.key === 'ArrowLeft') {
|
|
// Empêche le comportement par défaut de la touche
|
|
event.preventDefault();
|
|
|
|
// Cliquez sur le lien
|
|
previousArticleLink.click();
|
|
}
|
|
|
|
});
|
|
|
|
}); |