Skip to content

Commit 25fc617

Browse files
committed
fb_toggle
1 parent f4ab882 commit 25fc617

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
lines changed

scripts/fb_toggleLight.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ export const shared = {
3333
} else {
3434
el.style.display = el.style.display != "none" ? "none" : "";
3535
}
36-
} else alert("ERROR: Cannot find element");
36+
} else console.log("ERROR: Cannot find element");
3737
});
3838
},
3939
};

scripts/fb_toggleNewFeed.js

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
import {
2-
getCurrentTab,
3-
localStorage,
4-
runScriptInTab,
5-
} from "./helpers/utils.js";
6-
7-
const key = "ufs-fb-toggle-newfeed";
8-
91
export default {
102
icon: '<i class="fa-solid fa-eye-slash"></i>',
113
name: {
@@ -16,10 +8,7 @@ export default {
168
en: "Hide Newfeed facebook for better focus to work",
179
vi: "Ẩn Newfeed facebook để tập trung làm việc",
1810
},
19-
whiteList: ["https://www.facebook.com"],
20-
21-
getActive: async () => await localStorage.get(key),
22-
setActive: async (v) => await localStorage.set(key, v),
11+
whiteList: ["https://www.facebook.com/*"],
2312

2413
contentScript: {
2514
onDocumentIdle: function () {
@@ -34,12 +23,19 @@ export default {
3423

3524
export const shared = {
3625
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-
}
26+
[
27+
...Array.from(document.querySelectorAll("[role='feed'], [role='main']")),
28+
document.querySelector("#watch_feed"),
29+
document.querySelector("#ssrb_stories_start")?.parentElement,
30+
document.querySelector("#ssrb_feed_start")?.parentElement,
31+
].forEach((el) => {
32+
if (el) {
33+
if (willShow != null) {
34+
el.style.display = willShow ? "block" : "none";
35+
} else {
36+
el.style.display = el.style.display === "none" ? "block" : "none";
37+
}
38+
} else console.log("ERROR: Cannot find element");
39+
});
4440
},
4541
};

scripts/helpers/utils.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,21 +175,21 @@ export function checkBlackWhiteList(script, url) {
175175
return willRun;
176176
}
177177

178-
// https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
179178
export function isUrlMatchPattern(url, pattern) {
180-
return new URLPattern(pattern).test(url);
181-
182-
// if (pattern.indexOf("*") < 0)
183-
// return new URL(url).toString() == new URL(pattern).toString();
184-
185-
// let curIndex = 0,
186-
// visiblePartsInPattern = pattern.split("*").filter((_) => _ !== "");
187-
// for (let p of visiblePartsInPattern) {
188-
// let index = url.indexOf(p, curIndex);
189-
// if (index < 0) return false;
190-
// curIndex = index + p.length;
191-
// }
192-
// return true;
179+
// https://developer.mozilla.org/en-US/docs/Web/API/URL_Pattern_API
180+
// return new URLPattern(pattern).test(url);
181+
182+
if (pattern.indexOf("*") < 0)
183+
return new URL(url).toString() == new URL(pattern).toString();
184+
185+
let curIndex = 0,
186+
visiblePartsInPattern = pattern.split("*").filter((_) => _ !== "");
187+
for (let p of visiblePartsInPattern) {
188+
let index = url.indexOf(p, curIndex);
189+
if (index < 0) return false;
190+
curIndex = index + p.length;
191+
}
192+
return true;
193193
}
194194

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

0 commit comments

Comments
 (0)