From ff179027ddd9c830b7aa5ef0d4b6e1367176ba63 Mon Sep 17 00:00:00 2001 From: GaboFlo Date: Sat, 1 Nov 2025 12:25:52 +0100 Subject: [PATCH 1/2] Add 'disableCopyOnHover' feature to site settings and popup --- src/content.ts | 7 +++++++ src/popup.html | 5 +++++ src/popup.ts | 30 +++++++++++++++++++++++++----- 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/content.ts b/src/content.ts index a9b2a8c..d3157ec 100644 --- a/src/content.ts +++ b/src/content.ts @@ -15,6 +15,7 @@ interface ContentSettings { interface ContentSiteSettings { highlightAllWords?: boolean; + disableCopyOnHover?: boolean; } class HoverTranslator { @@ -241,6 +242,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(); 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"); From aba6cf5711de58317f3bc33f65ef1ccdad242311 Mon Sep 17 00:00:00 2001 From: GaboFlo Date: Sat, 1 Nov 2025 12:32:14 +0100 Subject: [PATCH 2/2] Implement hover delay for tooltip display in HoverTranslator class --- src/content.ts | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/content.ts b/src/content.ts index d3157ec..800e424 100644 --- a/src/content.ts +++ b/src/content.ts @@ -23,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; @@ -96,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) { @@ -187,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); } } @@ -505,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 {