diff --git a/addon/chrome/content/preferences.xhtml b/addon/chrome/content/preferences.xhtml index 13374311..0e4d39e6 100644 --- a/addon/chrome/content/preferences.xhtml +++ b/addon/chrome/content/preferences.xhtml @@ -45,6 +45,24 @@ preference="__prefsPrefix__.enableAnnotationFromSyncTranslation" /> + + + + + + + { + onPrefsEvents("setEnableAutoTagAnnotation"); + }); } function updatePrefsPaneDefault() { @@ -266,6 +272,7 @@ function updatePrefsPaneDefault() { onPrefsEvents("setUseWordService", false); onPrefsEvents("setSentenceSecret", false); onPrefsEvents("setWordSecret", false); + onPrefsEvents("setEnableAutoTagAnnotation", false); } function onPrefsEvents(type: string, fromElement: boolean = true) { @@ -336,6 +343,19 @@ function onPrefsEvents(type: string, fromElement: boolean = true) { } } break; + case "setEnableAutoTagAnnotation": + { + const elemValue = fromElement + ? ( + doc.querySelector( + `#${makeId("enableAutoTagAnnotation")}`, + ) as XUL.Checkbox + ).checked + : (getPref("enableAutoTagAnnotation") as boolean); + const hidden = !elemValue; + setDisabled("enable-auto-tag-annotation", hidden); + } + break; case "setSentenceService": { setPref( diff --git a/src/modules/services/index.ts b/src/modules/services/index.ts index 46b9b627..0b7e308b 100644 --- a/src/modules/services/index.ts +++ b/src/modules/services/index.ts @@ -343,6 +343,26 @@ export class TranslationServices { ? "annotationComment" : "annotationText" ] = text; + + // Auto tag + const enableAutoTag = getPref( + "enableAutoTagAnnotation", + ) as boolean; + if (enableAutoTag) { + const tagContent = getPref("annotationTagContent") as string; + if (tagContent && tagContent.trim()) { + const tag = tagContent.trim(); + // Check if the tag already exists + const existingTags = item.getTags(); + const tagExists = existingTags.some( + (existingTag) => existingTag.tag === tag, + ); + + if (!tagExists) { + item.addTag(tag); + } + } + } item.saveTx(); } } diff --git a/typings/i10n.d.ts b/typings/i10n.d.ts index 284af537..c9c24707 100644 --- a/typings/i10n.d.ts +++ b/typings/i10n.d.ts @@ -39,10 +39,12 @@ export type FluentMessageId = | 'pref-advanced-stripEmptyLines' | 'pref-audio-autoPlay' | 'pref-audio-showPlayBtn' + | 'pref-basic-annotationTagContent' | 'pref-basic-annotationTranslationInBody' | 'pref-basic-annotationTranslationInComment' | 'pref-basic-enableAnnotationFromSyncTranslation' | 'pref-basic-enableAuto' + | 'pref-basic-enableAutoTagAnnotation' | 'pref-basic-enableComment' | 'pref-basic-enableHidePopupTextarea' | 'pref-basic-enableNote' diff --git a/typings/prefs.d.ts b/typings/prefs.d.ts index 7fa63db3..6c2655c0 100644 --- a/typings/prefs.d.ts +++ b/typings/prefs.d.ts @@ -13,6 +13,8 @@ declare namespace _ZoteroTypes { "enablePopup": boolean; "enableComment": boolean; "enableAnnotationFromSyncTranslation": boolean; + "enableAutoTagAnnotation": boolean; + "annotationTagContent": string; "annotationTranslationPosition": string; "enableNote": boolean; "enableNoteReplaceMode": boolean;