From 16f423028d8e182808cb1a82bf86552ce51892a8 Mon Sep 17 00:00:00 2001 From: sienori Date: Mon, 8 Mar 2021 23:44:54 +0900 Subject: [PATCH] Add ignore code tag option --- src/_locales/en/messages.json | 6 ++++++ src/content/index.js | 4 ++-- src/settings/defaultSettings.js | 8 ++++++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 1915bfe..d60c9f9 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -98,6 +98,12 @@ "isDisabledInTextFieldsCaptionLabel": { "message": "Don't display translation button or panel when selecting text in a text field." }, + "isDisabledInCodeElementLabel": { + "message": "Disable translation in code tags" + }, + "isDisabledInCodeElementCaptionLabel": { + "message": "Don't display translation button or panel when selecting text in code tag." + }, "ifOnlyTranslateWhenModifierKeyPressedLabel": { "message": "Translate on modifier key pressed" }, diff --git a/src/content/index.js b/src/content/index.js index 0fe4f36..2ce2a75 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -27,8 +27,8 @@ const handleMouseUp = async e => { const isInPasswordField = e.target.tagName === "INPUT" && e.target.type === "password"; if (isInPasswordField) return; - const inCodeElement = e.target.tagName === 'CODE' || !!e.target.closest('code') - if (inCodeElement) return; + const inCodeElement = e.target.tagName === 'CODE' || !!e.target.closest('code'); + if (inCodeElement && getSettings("isDisabledInCodeElement")) return; const isInThisElement = document.querySelector("#simple-translate") && diff --git a/src/settings/defaultSettings.js b/src/settings/defaultSettings.js index f381902..30b67d7 100644 --- a/src/settings/defaultSettings.js +++ b/src/settings/defaultSettings.js @@ -147,6 +147,14 @@ export default [ type: "checkbox", default: false }, + { + id: "isDisabledInCodeElement", + title: "isDisabledInCodeElementLabel", + captions: ["isDisabledInCodeElementCaptionLabel"], + type: "checkbox", + default: false, + new: true + }, { id: "ignoredDocumentLang", title: "ignoredDocumentLangLabel",