Skip to content

Commit ac9ac89

Browse files
author
hoang.tran12
committed
urh .. . wip
1 parent f647427 commit ac9ac89

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+222
-274
lines changed

popup/tabs.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,6 @@ const tabs = [
816816
s.viewStylesUsed,
817817
s.cssSelectorViewer,
818818
s.viewPartialSource,
819-
s.consoleLog_withTime,
820819
createTitle("--- Remove ---", "--- Xoá ---"),
821820
s.removeColours,
822821
s.removeStylesheet,

scripts/_ufs_statistic.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default {
1616

1717
whiteList: ["https://useful-script-statistic.glitch.me/log*"],
1818

19-
pageScript: {
19+
contentScript: {
2020
onDocumentEnd: async () => {
2121
const logs = document.body.innerText
2222
.split("\n")

scripts/auto_redirectLargestImageSrc.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,13 @@ export default {
2222
"2024-04-16": "init",
2323
},
2424

25-
pageScript: {
25+
contentScript: {
2626
onDocumentStart: async () => {
2727
let oldHref = location.href;
2828
check(oldHref);
2929

30-
window.onload = () => {
31-
// listen location href change
32-
var bodyList = document.querySelector("body");
33-
var observer = new MutationObserver(function (mutations) {
34-
if (oldHref != document.location.href) {
35-
oldHref = document.location.href;
36-
check(oldHref);
37-
}
38-
});
39-
var config = {
40-
childList: true,
41-
subtree: true,
42-
};
43-
observer.observe(bodyList, config);
44-
};
30+
window.onload = () =>
31+
UfsGlobal.DOM.onHrefChanged((oldHref, newHref) => check(newHref));
4532

4633
async function check(href) {
4734
let url = await UfsGlobal.Utils.getLargestImageSrc(href, href);

scripts/changeAudioOutput.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
infoLink:
1212
"https://www.facebook.com/groups/j2team.community/posts/1362716140727169/",
1313

14-
pageScript: {
14+
contentScript: {
1515
// Source: https://gist.github.com/monokaijs/44ef4bd0770f83272b83c038a2769c90
1616
onClick: () => {
1717
(async function () {

scripts/checkWebDie.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
vi: "Dùng bên thứ 3 để kiểm tra xem website có bị die thật không",
1010
},
1111

12-
pageScript: {
12+
popupScript: {
1313
onClick: async function () {
1414
const { getCurrentTab } = await import("./helpers/utils.js");
1515
let { url } = await getCurrentTab();

scripts/consoleLog_withTime.js

Lines changed: 0 additions & 29 deletions
This file was deleted.

scripts/content-scripts/ufs_global.js

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -621,7 +621,7 @@ Call UseGlobal directly, no need to import
621621
});
622622
});
623623
}
624-
function deleteElements(selector, willReRun) {
624+
function deleteElements(selector, once) {
625625
onElementsVisible(
626626
selector,
627627
(nodes) => {
@@ -630,21 +630,35 @@ Call UseGlobal directly, no need to import
630630
console.log("Useful-scripts: element removed ", node);
631631
});
632632
},
633-
willReRun
633+
once
634634
);
635635
}
636636
function waitForElements(selector) {
637637
return new Promise((resolve, reject) => {
638-
onElementsVisible(selector, resolve, false);
638+
onElementsVisible(selector, resolve, true);
639639
});
640640
}
641+
// https://stackoverflow.com/a/46428962
642+
function onHrefChanged(callback, once) {
643+
let oldHref = document.location.href;
644+
const body = document.querySelector("body");
645+
const observer = new MutationObserver((mutations) => {
646+
let curHref = document.location.href;
647+
if (oldHref !== curHref) {
648+
callback?.(oldHref, curHref);
649+
oldHref = document.location.href;
650+
if (once) observer.disconnect();
651+
}
652+
});
653+
observer.observe(body, { childList: true, subtree: true });
654+
}
641655
// Idea from https://github.com/gys-dev/Unlimited-Stdphim
642656
// https://stackoverflow.com/a/61511955/11898496
643-
function onElementsVisible(selector, callback, willReRun) {
657+
function onElementsVisible(selector, callback, once) {
644658
let nodes = document.querySelectorAll(selector);
645659
if (nodes?.length) {
646660
callback(nodes);
647-
if (!willReRun) return;
661+
if (once) return;
648662
}
649663

650664
const observer = new MutationObserver((mutations) => {
@@ -660,7 +674,7 @@ Call UseGlobal directly, no need to import
660674

661675
if (n?.length) {
662676
callback(n);
663-
if (!willReRun) observer.disconnect();
677+
if (once) observer.disconnect();
664678
}
665679
}
666680
});

scripts/cssSelectorViewer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
vi: "Kiểm tra mã css cho thành phần bất kỳ trong trang web",
1010
},
1111

12-
pageScript: {
12+
contentScript: {
1313
onClick: function () {
1414
var s = document.createElement("div");
1515
s.innerHTML = "Loading...";

scripts/darkModePDF.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default {
99
vi: "Bật/Tắt chế độ tối cho PDF bạn đang xem",
1010
},
1111

12-
pageScript: {
12+
contentScript: {
1313
onClick: function () {
1414
let id = "useful-scripts-darkModePDF";
1515

scripts/detect_zeroWidthCharacters.js

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export default {
1111
infoLink:
1212
"https://viblo.asia/p/ky-tu-zero-width-sat-thu-vo-hinh-nam-giua-doan-van-ban-thuan-vo-hai-L4x5xM7qKBM",
1313

14-
pageScript: {
14+
contentScript: {
1515
onDocumentIdle: detectZeroWidthCharacters,
1616
onClick: detectZeroWidthCharacters,
1717
},
@@ -49,10 +49,12 @@ function detectZeroWidthCharacters() {
4949
);
5050
const regExp = new RegExp(`([${zeroWidthCharacters}])`, "g");
5151
let textToAdd = '<span class="' + spanClass + '"></span>';
52-
element.classList.add(containerClass);
53-
element.innerHTML = element.innerHTML
54-
.replace(textToAdd, "")
55-
.replace(regExp, "$1" + textToAdd);
52+
let preHighlight = element.querySelectorAll(`span.${spanClass}`);
53+
preHighlight.forEach((el) => {
54+
el.remove();
55+
});
56+
element.classList.toggle(containerClass, true);
57+
element.innerHTML = element.innerHTML.replace(regExp, "$1" + textToAdd);
5658
};
5759
// From: https://jsfiddle.net/tim333/np874wae/13/
5860
const checkElement = function (element) {
@@ -90,7 +92,9 @@ function detectZeroWidthCharacters() {
9092
(async () => {
9193
// inject css
9294
UfsGlobal.DOM.injectCssFile(
93-
await UfsGlobal.Extension.getURL("scripts/detect_zeroWidthCharacters.css")
95+
await UfsGlobal.Extension.getURL(
96+
"/scripts/detect_zeroWidthCharacters.css"
97+
)
9498
);
9599

96100
// Check Page

0 commit comments

Comments
 (0)