Fixed mouse event error (TypeError: e.target.closest is not a function) (#355)

This commit is contained in:
Denis 2022-03-02 14:16:04 +02:00 committed by GitHub
parent 46b1a33e1d
commit 953343e663
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -28,7 +28,7 @@ const handleMouseUp = async e => {
const isInPasswordField = e.target.tagName === "INPUT" && e.target.type === "password"; const isInPasswordField = e.target.tagName === "INPUT" && e.target.type === "password";
if (isInPasswordField) return; if (isInPasswordField) return;
const inCodeElement = e.target.tagName === "CODE" || !!e.target.closest("code"); const inCodeElement = e.target.tagName === "CODE" || (!!e.target.closest && !!e.target.closest("code"));
if (inCodeElement && getSettings("isDisabledInCodeElement")) return; if (inCodeElement && getSettings("isDisabledInCodeElement")) return;
const isInThisElement = const isInThisElement =
@ -41,7 +41,7 @@ const handleMouseUp = async e => {
const ignoredDocumentLang = getSettings("ignoredDocumentLang").split(",").map(s => s.trim()).filter(s => !!s); const ignoredDocumentLang = getSettings("ignoredDocumentLang").split(",").map(s => s.trim()).filter(s => !!s);
if (ignoredDocumentLang.length) { if (ignoredDocumentLang.length) {
const ignoredLangSelector = ignoredDocumentLang.map(lang => `[lang="${lang}"]`).join(',') const ignoredLangSelector = ignoredDocumentLang.map(lang => `[lang="${lang}"]`).join(',')
if (!!e.target.closest(ignoredLangSelector)) return; if (!!e.target.closest && !!e.target.closest(ignoredLangSelector)) return;
} }
const selectedText = getSelectedText(); const selectedText = getSelectedText();