Skip to content

Commit 3ccdec7

Browse files
author
hoang.tran12
committed
urlpattern
1 parent d10a9a6 commit 3ccdec7

File tree

2 files changed

+22
-21
lines changed

2 files changed

+22
-21
lines changed

scripts/fb_toggleNewFeed.js

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,13 @@ export default {
3333
};
3434

3535
export const shared = {
36-
toggleNewFeed: async function (willShow, tabId) {
37-
runScriptInTab({
38-
tabId: tabId || (await getCurrentTab()).id,
39-
args: [willShow],
40-
func: (value) => {
41-
let div = document.querySelector("#ssrb_feed_end")?.parentElement;
42-
if (!div) alert("Không tìm thấy NewFeed.");
43-
else {
44-
div.style.display =
45-
value ?? div.style.display === "none" ? "block" : "none";
46-
}
47-
},
48-
});
36+
toggleNewFeed: async function (willShow) {
37+
let div = document.querySelector("#ssrb_feed_end")?.parentElement;
38+
if (!div) alert("Không tìm thấy NewFeed.");
39+
else if (willShow != null) {
40+
div.style.display = willShow ? "block" : "none";
41+
} else {
42+
div.style.display = div.style.display === "none" ? "block" : "none";
43+
}
4944
},
5045
};

scripts/helpers/utils.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,15 +162,21 @@ export function checkBlackWhiteList(script, url) {
162162
return willRun;
163163
}
164164

165+
// https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
165166
export function isUrlMatchPattern(url, pattern) {
166-
let curIndex = 0,
167-
visiblePartsInPattern = pattern.split("*").filter((_) => _ !== "");
168-
for (let p of visiblePartsInPattern) {
169-
let index = url.indexOf(p, curIndex);
170-
if (index < 0) return false;
171-
curIndex = index + p.length;
172-
}
173-
return true;
167+
return new URLPattern(pattern).test(url);
168+
169+
// if (pattern.indexOf("*") < 0)
170+
// return new URL(url).toString() == new URL(pattern).toString();
171+
172+
// let curIndex = 0,
173+
// visiblePartsInPattern = pattern.split("*").filter((_) => _ !== "");
174+
// for (let p of visiblePartsInPattern) {
175+
// let index = url.indexOf(p, curIndex);
176+
// if (index < 0) return false;
177+
// curIndex = index + p.length;
178+
// }
179+
// return true;
174180
}
175181

176182
// https://stackoverflow.com/a/68634884/11898496

0 commit comments

Comments
 (0)