diff --git a/src/content.ts b/src/content.ts index a9b2a8c..800e424 100644 --- a/src/content.ts +++ b/src/content.ts @@ -15,6 +15,7 @@ interface ContentSettings { interface ContentSiteSettings { highlightAllWords?: boolean; + disableCopyOnHover?: boolean; } class HoverTranslator { @@ -22,6 +23,7 @@ class HoverTranslator { private translations: ContentTranslationData = {}; private targetUrls: string[] = []; + private delay: number = 300; private hoverTimeout: number | null = null; private currentHoveredElement: HTMLElement | null = null; private tooltip: HTMLElement | null = null; @@ -95,6 +97,7 @@ class HoverTranslator { this.translations = translations; this.targetUrls = result.targetUrls || []; this.isEnabled = result.isEnabled !== false; + this.delay = result.delay ?? 300; this.siteSettings = result.siteSettings || {}; this.currentDomain = window.location.hostname; } catch (error) { @@ -186,13 +189,22 @@ class HoverTranslator { const allTranslations = this.findAllTranslations(text); if (allTranslations.length > 0) { - // Retirer l'ancienne bordure et ajouter la nouvelle + // Annuler le timeout précédent s'il existe + if (this.hoverTimeout) { + clearTimeout(this.hoverTimeout); + this.hoverTimeout = null; + } + + // Retirer l'ancienne bordure immédiatement this.removeTranslationBorder(); - this.addMultipleTranslationBorders(target, text, allTranslations); - // Afficher le tooltip avec toutes les traductions - const tooltipText = this.formatMultipleTranslations(allTranslations); - this.showTooltip(tooltipText, event); + // Utiliser un timeout pour afficher les bordures, surlignages et tooltip après le délai + this.hoverTimeout = window.setTimeout(() => { + this.addMultipleTranslationBorders(target, text, allTranslations); + + const tooltipText = this.formatMultipleTranslations(allTranslations); + this.showTooltipImmediate(tooltipText, event); + }, this.delay); } } @@ -241,6 +253,12 @@ class HoverTranslator { target.hasAttribute("data-auto-highlight") || target.hasAttribute("data-hover-translator-highlight") ) { + // Vérifier si le copier-coller est désactivé pour ce site + const currentSiteSettings = this.siteSettings[this.currentDomain]; + if (currentSiteSettings?.disableCopyOnHover) { + return; + } + event.preventDefault(); event.stopPropagation(); @@ -498,18 +516,12 @@ class HoverTranslator { }); } - private showTooltip(translation: string, event: MouseEvent): void { - if (this.hoverTimeout) { - clearTimeout(this.hoverTimeout); + private showTooltipImmediate(translation: string, event: MouseEvent): void { + if (this.tooltip) { + this.tooltip.textContent = translation; + this.tooltip.style.opacity = "1"; + this.positionTooltip(event); } - - this.hoverTimeout = window.setTimeout(() => { - if (this.tooltip) { - this.tooltip.textContent = translation; - this.tooltip.style.opacity = "1"; - this.positionTooltip(event); - } - }, 300); } private hideTooltip(): void { diff --git a/src/popup.html b/src/popup.html index 9452bab..c1d8b83 100644 --- a/src/popup.html +++ b/src/popup.html @@ -37,6 +37,11 @@

🔤 Traducteur personnalisé au survol

Surligner tous les mots connus + diff --git a/src/popup.ts b/src/popup.ts index 63bd248..f01a595 100644 --- a/src/popup.ts +++ b/src/popup.ts @@ -14,6 +14,7 @@ interface PopupSettings { interface SiteSettings { highlightAllWords?: boolean; + disableCopyOnHover?: boolean; } interface PopupElements { @@ -23,6 +24,7 @@ interface PopupElements { removeCurrentSite: HTMLButtonElement; currentSiteUrl: HTMLInputElement; highlightAllWords: HTMLInputElement; + disableCopyOnHover: HTMLInputElement; infoSection: HTMLDivElement; siteOptionsSection: HTMLDivElement; } @@ -60,6 +62,9 @@ class PopupManager { highlightAllWords: document.getElementById( "highlightAllWords" ) as HTMLInputElement, + disableCopyOnHover: document.getElementById( + "disableCopyOnHover" + ) as HTMLInputElement, infoSection: document.getElementById("infoSection") as HTMLDivElement, siteOptionsSection: document.getElementById( "siteOptionsSection" @@ -84,6 +89,10 @@ class PopupManager { this.elements.highlightAllWords.addEventListener("change", () => { this.updateSiteSettings(); }); + + this.elements.disableCopyOnHover.addEventListener("change", () => { + this.updateSiteSettings(); + }); } catch (error) { console.error( "❌ Erreur lors de la liaison des événements popup:", @@ -142,6 +151,8 @@ class PopupManager { const currentSiteSettings = siteSettings[currentDomain] || {}; this.elements.highlightAllWords.checked = currentSiteSettings.highlightAllWords || false; + this.elements.disableCopyOnHover.checked = + currentSiteSettings.disableCopyOnHover || false; // Afficher le statut spécifique au site actuel if (isActiveOnCurrentSite) { @@ -366,6 +377,8 @@ class PopupManager { siteSettings[domain] ??= {}; siteSettings[domain].highlightAllWords = this.elements.highlightAllWords.checked; + siteSettings[domain].disableCopyOnHover = + this.elements.disableCopyOnHover.checked; // Sauvegarder await chrome.storage.sync.set({ siteSettings }); @@ -380,11 +393,18 @@ class PopupManager { await chrome.tabs.reload(activeTab.id); } - this.showNotification( - this.elements.highlightAllWords.checked - ? "Surlignage automatique activé" - : "Surlignage automatique désactivé" - ); + const messages: string[] = []; + if (this.elements.highlightAllWords.checked) { + messages.push("Surlignage automatique activé"); + } else { + messages.push("Surlignage automatique désactivé"); + } + if (this.elements.disableCopyOnHover.checked) { + messages.push("Copier-coller au hover désactivé"); + } else { + messages.push("Copier-coller au hover activé"); + } + this.showNotification(messages.join(" - ")); } catch (error) { console.error("Erreur lors de la mise à jour des paramètres:", error); this.showNotification("Erreur lors de la mise à jour");