Skip to content

Commit

Permalink
🐛 fix(UrlAutoHelper): fix url validation
Browse files Browse the repository at this point in the history
  • Loading branch information
kmou424 committed Jul 19, 2023
1 parent c7a8906 commit 38e417e
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions UrlAutoHelper/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,18 @@ const RunScript = async () => {
}, 500);
};

const isInvalidHref = (href: string): boolean => {
return href.startsWith('javascript:') || href.endsWith("/#") || href === '';
};

const RunBlankPatch = async () => {
BlankPatchMutex.lock();

const aTags = document.getElementsByTagName("a");

// @ts-ignore
for (const aTag of aTags) {
// console.log(document.URL + "#")
if (aTag.href.startsWith('javascript:') || aTag.href.startsWith(document.URL + "/#") || aTag.href === '') {
if (isInvalidHref(aTag.href)) {
continue;
}
const url = new URL(aTag.href).toString();
Expand Down Expand Up @@ -90,7 +93,7 @@ const RunAutoOpen = async () => {

// @ts-ignore
for (const aTag of aTags) {
if (aTag.href.startsWith('javascript:') || aTag.href.startsWith(document.URL + "/#") || aTag.href === '') {
if (isInvalidHref(aTag.href)) {
continue;
}
const url = new URL(aTag.href).toString();
Expand Down

0 comments on commit 38e417e

Please sign in to comment.