From 2bb8a5182cd8419bc7e0cefd65115888c5a3545c Mon Sep 17 00:00:00 2001 From: Gabe Date: Wed, 5 Nov 2025 20:48:12 +0800 Subject: [PATCH] fix: Some element tagnames are lowercase. (#377) --- src/common.js | 4 ++++ src/content.js | 4 +--- src/libs/translator.js | 7 +++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/common.js b/src/common.js index 275e178..ab92551 100644 --- a/src/common.js +++ b/src/common.js @@ -118,6 +118,10 @@ async function getFavWords(rule) { */ export async function run(isUserscript = false) { try { + if (document?.documentElement?.tagName?.toUpperCase() !== "HTML") { + return; + } + // 读取设置信息 const setting = await getSettingWithDefault(); diff --git a/src/content.js b/src/content.js index ba58646..3dc1433 100644 --- a/src/content.js +++ b/src/content.js @@ -1,5 +1,3 @@ import { run } from "./common"; -if (document.documentElement && document.documentElement.tagName === "HTML") { - run(); -} +run(); diff --git a/src/libs/translator.js b/src/libs/translator.js index bd8ef61..595b308 100644 --- a/src/libs/translator.js +++ b/src/libs/translator.js @@ -1322,7 +1322,10 @@ export class Translator { // node.matches(this.#ignoreSelector) || !node.textContent.trim() ) { - if (node.tagName === "IMG" || node.tagName === "SVG") { + if ( + node.tagName?.toUpperCase() === "IMG" || + node.tagName?.toUpperCase() === "SVG" + ) { node.style.width = `${node.offsetWidth}px`; node.style.height = `${node.offsetHeight}px`; } @@ -1336,7 +1339,7 @@ export class Translator { if ( this.#rule.hasRichText === "true" && - Translator.TAGS.WARP.has(node.tagName) + Translator.TAGS.WARP.has(node.tagName?.toUpperCase()) ) { wrapCounter++; const startPlaceholder = `<${this.#placeholder.tagName}${wrapCounter}>`;