Skip to content

Commit

Permalink
🐛 fix(UrlAutoHelper): update hash of a tag after innerText changed
Browse files Browse the repository at this point in the history
  • Loading branch information
kmou424 committed Jul 18, 2023
1 parent ff641c8 commit ef4bf2a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
8 changes: 8 additions & 0 deletions UrlAutoHelper/src/lib/crypto/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
7 changes: 5 additions & 2 deletions UrlAutoHelper/src/lib/crypto/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
import {Crypto} from "./crypto";
import {Crypto, DOMCrypto} from "./crypto";

export default Crypto;
export {
Crypto,
DOMCrypto
};
8 changes: 5 additions & 3 deletions UrlAutoHelper/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -108,6 +108,8 @@ const RunAutoOpen = async () => {
const stored = await KVStorage.getByPath<boolean>(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<boolean>(valuePath, true);
Expand Down

0 comments on commit ef4bf2a

Please sign in to comment.