From f20990894a6d7bacbc276a1f920aaacd0e7502a1 Mon Sep 17 00:00:00 2001 From: Alex Kozack Date: Tue, 27 Apr 2021 15:41:26 +0300 Subject: [PATCH] Language definition based on the closest `lang` attribute (#297) * Language definition based on the closest `lang` attribute * Update index.js --- src/content/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/content/index.js b/src/content/index.js index 806cff4..dab2449 100644 --- a/src/content/index.js +++ b/src/content/index.js @@ -38,7 +38,10 @@ const handleMouseUp = async e => { removeTranslatecontainer(); const ignoredDocumentLang = getSettings("ignoredDocumentLang").split(",").map(s => s.trim()).filter(s => !!s); - if (!!document.documentElement.lang && ignoredDocumentLang.includes(document.documentElement.lang)) return; + if (ignoredDocumentLang.length) { + const ignoredLangSelector = ignoredDocumentLang.map(lang => `[lang="${lang}"]`).join(',') + if (!!e.target.closest(ignoredLangSelector)) return; + } const selectedText = getSelectedText(); prevSelectedText = selectedText;