From a44747ccadc01f05033c138a55a274363f4325a4 Mon Sep 17 00:00:00 2001 From: Gabe Yuan Date: Tue, 5 Sep 2023 16:06:48 +0800 Subject: [PATCH] fix herf match func --- src/content.js | 3 ++- src/libs/utils.js | 9 ++++++++- src/userscript.js | 3 ++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/content.js b/src/content.js index 509fdb8..aca2d54 100644 --- a/src/content.js +++ b/src/content.js @@ -45,9 +45,10 @@ const init = async () => { try { await init(); } catch (err) { + console.error("[KISS-Translator]", err); const $err = document.createElement("div"); $err.innerText = `KISS-Translator: ${err.message}`; - $err.style.cssText = "background:red; color:#fff; z-index:10000;"; + $err.style.cssText = "background:red; color:#fff;"; document.body.prepend($err); } })(); diff --git a/src/libs/utils.js b/src/libs/utils.js index fe13afc..389f81d 100644 --- a/src/libs/utils.js +++ b/src/libs/utils.js @@ -91,7 +91,14 @@ export const isMatch = (s, p) => { return true; } - return p.slice(pIndex).replaceAll("*", "") === ""; + while (pIndex < p.length) { + if (p[pIndex] !== "*") { + return false; + } + pIndex++; + } + + return true; }; /** diff --git a/src/userscript.js b/src/userscript.js index 31281ba..f212c50 100644 --- a/src/userscript.js +++ b/src/userscript.js @@ -99,9 +99,10 @@ const init = async () => { try { await init(); } catch (err) { + console.error("[KISS-Translator]", err); const $err = document.createElement("div"); $err.innerText = `KISS-Translator: ${err.message}`; - $err.style.cssText = "background:red; color:#fff; z-index:10000;"; + $err.style.cssText = "background:red; color:#fff;"; document.body.prepend($err); } })();