From ef4bf2ad9aa2a1726063f34fa04ef191ae706c9d Mon Sep 17 00:00:00 2001 From: kmou424 Date: Tue, 18 Jul 2023 16:43:42 +0800 Subject: [PATCH] :bug: fix(UrlAutoHelper): update hash of a tag after innerText changed --- UrlAutoHelper/src/lib/crypto/crypto.ts | 8 ++++++++ UrlAutoHelper/src/lib/crypto/index.ts | 7 +++++-- UrlAutoHelper/src/main.ts | 8 +++++--- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/UrlAutoHelper/src/lib/crypto/crypto.ts b/UrlAutoHelper/src/lib/crypto/crypto.ts index a0cbdcb..9bed268 100644 --- a/UrlAutoHelper/src/lib/crypto/crypto.ts +++ b/UrlAutoHelper/src/lib/crypto/crypto.ts @@ -5,4 +5,12 @@ export class Crypto { static MD5(input: string): string { return CryptoJS.MD5(input).toString().toLowerCase(); } +} + +export class DOMCrypto { + private static readonly serializer = new XMLSerializer(); + + static MD5(input: Node): string { + return Crypto.MD5(this.serializer.serializeToString(input)); + } } \ No newline at end of file diff --git a/UrlAutoHelper/src/lib/crypto/index.ts b/UrlAutoHelper/src/lib/crypto/index.ts index 4372a3b..f7e1cdb 100644 --- a/UrlAutoHelper/src/lib/crypto/index.ts +++ b/UrlAutoHelper/src/lib/crypto/index.ts @@ -1,3 +1,6 @@ -import {Crypto} from "./crypto"; +import {Crypto, DOMCrypto} from "./crypto"; -export default Crypto; \ No newline at end of file +export { + Crypto, + DOMCrypto +}; \ No newline at end of file diff --git a/UrlAutoHelper/src/main.ts b/UrlAutoHelper/src/main.ts index a27df69..c0ab1d4 100644 --- a/UrlAutoHelper/src/main.ts +++ b/UrlAutoHelper/src/main.ts @@ -4,7 +4,7 @@ import {AUTO_OPEN, BLANK_PATCH} from "./config"; import Logcat from "./logcat"; import {Pattern, PatternMatcher, TYPE_MULTI_WILDCARD} from "./lib/pattern"; import {GM_openInTab} from "$"; -import Crypto from "./lib/crypto"; +import {Crypto, DOMCrypto} from "./lib/crypto"; import {KVStorage} from "./lib/storage"; import {ValuePath} from "./type"; import {APP_NAME} from "./const"; @@ -57,7 +57,7 @@ const RunBlankPatch = async () => { continue; } const url = new URL(aTag.href).toString(); - const hashOfATag = Crypto.MD5(new XMLSerializer().serializeToString(aTag)); + const hashOfATag = DOMCrypto.MD5(aTag); if (BlankPatchRecorder.get(hashOfATag)) { continue; @@ -94,7 +94,7 @@ const RunAutoOpen = async () => { continue; } const url = new URL(aTag.href).toString(); - const hashOfATag = Crypto.MD5(new XMLSerializer().serializeToString(aTag)); + let hashOfATag = DOMCrypto.MD5(aTag); if (AutoOpenRecorder.get(hashOfATag)) { continue; @@ -108,6 +108,8 @@ const RunAutoOpen = async () => { const stored = await KVStorage.getByPath(valuePath, false); if (stored) { aTag.text = `(${I18n.get(I18nKeys.UI_VISITED)}) ${aTag.text}`; + // update hash because innerText has been changed + hashOfATag = DOMCrypto.MD5(aTag); } else { GM_openInTab(url); await KVStorage.setByPath(valuePath, true);