mirror of
				https://forge.chapril.org/tykayn/orgmode-to-gemini-blog
				synced 2025-10-09 17:02:45 +02:00 
			
		
		
		
	
		
			
				
	
	
		
			116 lines
		
	
	
		
			No EOL
		
	
	
		
			4.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			116 lines
		
	
	
		
			No EOL
		
	
	
		
			4.2 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| // search bar to send a request to a search engine for the current domain when sent
 | |
| document.addEventListener('DOMContentLoaded', function () {
 | |
|     // Charger le thème depuis localStorage au plus tôt
 | |
|     try {
 | |
|         const savedTheme = localStorage.getItem('tkTheme');
 | |
|         if (savedTheme && typeof savedTheme === 'string') {
 | |
|             document.body.className = savedTheme;
 | |
|             window.currentThemeIndex = 0; // sera recalculé au clic
 | |
|         }
 | |
|     } catch (e) {
 | |
|         // ignore stockage indisponible
 | |
|     }
 | |
| 
 | |
|     // 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'
 | |
|     if (form) {
 | |
|         form.addEventListener('submit', function (event) {
 | |
|             // Empêche le comportement par défaut du formulaire
 | |
|             event.preventDefault()
 | |
|             const input = form.querySelector('.search-field');
 | |
|             const query = input ? input.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 si présents
 | |
|     if (nextArticleLink) {
 | |
|         nextArticleLink.addEventListener('click', function () {
 | |
|             // Redirigez l'utilisateur vers la page suivante
 | |
|             window.location.href = nextArticleLink.href;
 | |
|         });
 | |
|     }
 | |
|     if (previousArticleLink) {
 | |
|         previousArticleLink.addEventListener('click', function () {
 | |
|             // Redirigez l'utilisateur vers la page précédente
 | |
|             window.location.href = previousArticleLink.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
 | |
|             if (nextArticleLink) 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
 | |
|             if (previousArticleLink) previousArticleLink.click();
 | |
|         }
 | |
| 
 | |
|     });
 | |
| 
 | |
|    const themes_calsses = ['default', 'mastodon', 'another']
 | |
| 
 | |
|     function makeThemesButton(){
 | |
| 
 | |
|     // Crée un bouton pour changer de thème et l'ajoute au body
 | |
|     const boutonTheme = document.createElement('button');
 | |
|     boutonTheme.textContent = 'Changer de thème';
 | |
|     boutonTheme.id = 'theme-switcher';
 | |
|     document.body.appendChild(boutonTheme);
 | |
|     console.log('boutonTheme', boutonTheme);
 | |
|     console.log('themes_calsses', themes_calsses);
 | |
|     boutonTheme.addEventListener('click', onClickThemeButton)
 | |
| }
 | |
| 
 | |
| 
 | |
|     function onClickThemeButton(){
 | |
| 
 | |
|     // Passer au thème suivant et appliquer la classe au body
 | |
|     // On suppose que themes_calsses est un tableau global
 | |
|     if (!window.currentThemeIndex && window.currentThemeIndex !== 0) {
 | |
|         // Initialiser l'index du thème courant en fonction de la classe actuelle du body
 | |
|         const currentClass = document.body.className;
 | |
|         window.currentThemeIndex = themes_calsses.indexOf(currentClass);
 | |
|         if (window.currentThemeIndex === -1) {
 | |
|             window.currentThemeIndex = 0;
 | |
|         }
 | |
|     }
 | |
|     // Passer au thème suivant
 | |
|     window.currentThemeIndex = (window.currentThemeIndex + 1) % themes_calsses.length;
 | |
|     // Appliquer la nouvelle classe au body
 | |
|     const newTheme = themes_calsses[window.currentThemeIndex];
 | |
|     document.body.className = newTheme;
 | |
| 
 | |
|     // Sauvegarder le thème choisi
 | |
|     try {
 | |
|         localStorage.setItem('tkTheme', newTheme);
 | |
|     } catch (e) {
 | |
|         // ignore stockage indisponible
 | |
|     }
 | |
|     }
 | |
| 
 | |
| 
 | |
|     // créer le bouton thème au chargement
 | |
|     makeThemesButton();
 | |
| }); | 
