From 204fb8e6b025b2e410a5d955cd43b564738fffa3 Mon Sep 17 00:00:00 2001
From: HoangTran <99.hoangtran@gmail.com>
Date: Sun, 7 Apr 2024 10:31:09 +0700
Subject: [PATCH 1/3] show video tag
---
scripts/ggDrive_downloadAllVideosInFolder.js | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/scripts/ggDrive_downloadAllVideosInFolder.js b/scripts/ggDrive_downloadAllVideosInFolder.js
index e8b5bdde..234e9f5f 100644
--- a/scripts/ggDrive_downloadAllVideosInFolder.js
+++ b/scripts/ggDrive_downloadAllVideosInFolder.js
@@ -65,7 +65,8 @@ export default {
.map(({ quality, url }) => {
if (!(quality in allUrls)) allUrls[quality] = [];
allUrls[quality].push(url);
- return `${quality}`;
+ return /* html */ `${quality}
+ `;
})
.join("
");
From 7b3bd6cfbbd434d6cfe78e9a5265c717541b7240 Mon Sep 17 00:00:00 2001
From: HoangTran <99.hoangtran@gmail.com>
Date: Sun, 7 Apr 2024 18:47:57 +0700
Subject: [PATCH 2/3] fix
---
manifest.json | 24 ++++-
popup/tabs.js | 4 +-
scripts/content-scripts/content_script.js | 54 ++++++++++
scripts/content-scripts/document_end.js | 7 +-
scripts/content-scripts/document_idle.js | 7 +-
scripts/content-scripts/document_start.js | 100 +-----------------
scripts/content-scripts/run_scripts.js | 35 +++---
.../scripts/ufs_global_webpage_context.js | 5 +
scripts/fb_messengerCount.js | 6 +-
scripts/fb_searchGroupForOther.js | 6 +-
scripts/fb_searchPageForOther.js | 6 +-
11 files changed, 102 insertions(+), 152 deletions(-)
create mode 100644 scripts/content-scripts/content_script.js
diff --git a/manifest.json b/manifest.json
index db6823bc..e5178a73 100644
--- a/manifest.json
+++ b/manifest.json
@@ -35,21 +35,39 @@
},
{
"matches": [""],
- "js": ["scripts/content-scripts/document_start.js"],
+ "js": ["scripts/content-scripts/scripts/ufs_global_webpage_context.js"],
"run_at": "document_start",
"world": "ISOLATED"
},
+ {
+ "matches": [""],
+ "js": ["scripts/content-scripts/content_script.js"],
+ "run_at": "document_start",
+ "world": "ISOLATED"
+ },
+ {
+ "matches": [""],
+ "js": ["scripts/content-scripts/run_scripts.js"],
+ "run_at": "document_start",
+ "world": "MAIN"
+ },
+ {
+ "matches": [""],
+ "js": ["scripts/content-scripts/document_start.js"],
+ "run_at": "document_start",
+ "world": "MAIN"
+ },
{
"matches": [""],
"js": ["scripts/content-scripts/document_idle.js"],
"run_at": "document_idle",
- "world": "ISOLATED"
+ "world": "MAIN"
},
{
"matches": [""],
"js": ["scripts/content-scripts/document_end.js"],
"run_at": "document_end",
- "world": "ISOLATED"
+ "world": "MAIN"
}
],
"web_accessible_resources": [
diff --git a/popup/tabs.js b/popup/tabs.js
index c8d97238..8d47207e 100644
--- a/popup/tabs.js
+++ b/popup/tabs.js
@@ -106,9 +106,9 @@ const tabs = [
s.fb_downloadCommentVideo,
s.fb_videoDownloader,
s.fb_getAvatarFromUid,
- s.fb_storyInfo,
+ // s.fb_storyInfo,
createTitle("--- Bulk Download ---", "--- Tải hàng loạt ---"),
- s.fb_bulkDownload,
+ // s.fb_bulkDownload,
s.fb_downloadAlbumMedia,
s.fb_downloadWallMediaFromPosts,
s.fb_getAllAlbumInformation,
diff --git a/scripts/content-scripts/content_script.js b/scripts/content-scripts/content_script.js
new file mode 100644
index 00000000..bb55e48f
--- /dev/null
+++ b/scripts/content-scripts/content_script.js
@@ -0,0 +1,54 @@
+// communication between page-script and content-script
+(() => {
+ function sendToPageScript(event, data) {
+ window.dispatchEvent(
+ new CustomEvent("ufs-contentscript-sendto-pagescript", {
+ detail: { event, data },
+ })
+ );
+ }
+ window.addEventListener("ufs-pagescript-sendto-contentscript", async (e) => {
+ let { event, data } = e.detail;
+ switch (event) {
+ case "getURL":
+ sendToPageScript(event, chrome.runtime.getURL(data));
+ break;
+ case "getActiveScripts":
+ const key = "activeScripts";
+ let ids = (await chrome.storage.sync.get([key]))?.[key] || "";
+ let path = chrome.runtime.getURL("/scripts/");
+ sendToPageScript(event, { ids, path });
+ break;
+ }
+ });
+})();
+
+// Run script on user click (if clicked script has onClickContentScript event)
+(async () => {
+ try {
+ const { MsgType, ClickType } = await import("../helpers/constants.js");
+ const { isFunction } = await import("../helpers/utils.js");
+
+ chrome.runtime.onMessage.addListener(async function (
+ message,
+ sender,
+ sendResponse
+ ) {
+ console.log("> Received message:", message);
+
+ switch (message.type) {
+ case MsgType.runScript:
+ let scriptId = message.scriptId;
+ const script = (await import("../" + scriptId + ".js"))?.default;
+
+ if (script && isFunction(script[ClickType.onClickContentScript])) {
+ script[ClickType.onClickContentScript]();
+ console.log("> Run script " + scriptId);
+ }
+ break;
+ }
+ });
+ } catch (e) {
+ console.log("ERROR: ", e);
+ }
+})();
diff --git a/scripts/content-scripts/document_end.js b/scripts/content-scripts/document_end.js
index 876935cc..5fa607d0 100644
--- a/scripts/content-scripts/document_end.js
+++ b/scripts/content-scripts/document_end.js
@@ -1,12 +1,7 @@
(async () => {
- let key = "activeScripts";
- let ids = (await chrome.storage.sync.get([key]))?.[key] || "";
window.dispatchEvent(
new CustomEvent("ufs-run-page-scripts", {
- detail: {
- event: "onDocumentEnd",
- ids: ids.split(","),
- },
+ detail: { event: "onDocumentEnd" },
})
);
})();
diff --git a/scripts/content-scripts/document_idle.js b/scripts/content-scripts/document_idle.js
index e9607fbc..10a4b90a 100644
--- a/scripts/content-scripts/document_idle.js
+++ b/scripts/content-scripts/document_idle.js
@@ -1,12 +1,7 @@
(async () => {
- let key = "activeScripts";
- let ids = (await chrome.storage.sync.get([key]))?.[key] || "";
window.dispatchEvent(
new CustomEvent("ufs-run-page-scripts", {
- detail: {
- event: "onDocumentIdle",
- ids: ids.split(","),
- },
+ detail: { event: "onDocumentIdle" },
})
);
})();
diff --git a/scripts/content-scripts/document_start.js b/scripts/content-scripts/document_start.js
index 17f5c0ed..7633e835 100644
--- a/scripts/content-scripts/document_start.js
+++ b/scripts/content-scripts/document_start.js
@@ -1,102 +1,8 @@
-// communication between page-script and content-script
-(() => {
- function sendToPageScript(event, data) {
- window.dispatchEvent(
- new CustomEvent("ufs-contentscript-sendto-pagescript", {
- detail: { event, data },
- })
- );
- }
- window.addEventListener("ufs-pagescript-sendto-contentscript", (e) => {
- let { event, data } = e.detail;
- switch (event) {
- case "getURL":
- sendToPageScript(event, chrome.runtime.getURL(data));
- break;
- }
- });
-})();
-
// run all scripts that has onDocumentStart event
(async () => {
- import(
- chrome.runtime.getURL(
- "/scripts/content-scripts/scripts/ufs_global_webpage_context.js"
- )
- );
-
- let key = "activeScripts";
- let ids = (await chrome.storage.sync.get([key]))?.[key] || "";
- let path = chrome.runtime.getURL("/scripts/");
-
- localStorage.setItem(
- "ufs-auto-run-scripts",
- JSON.stringify({
- ids: ids,
- path: path,
- event: "onDocumentStart",
+ window.dispatchEvent(
+ new CustomEvent("ufs-run-page-scripts", {
+ detail: { event: "onDocumentStart" },
})
);
-
- import(chrome.runtime.getURL("/scripts/content-scripts/run_scripts.js"));
-})();
-
-// Run script on user click (if clicked script has onClickContentScript event)
-(async () => {
- try {
- const { MsgType, ClickType } = await import("../helpers/constants.js");
- const { isFunction } = await import("../helpers/utils.js");
-
- chrome.runtime.onMessage.addListener(async function (
- message,
- sender,
- sendResponse
- ) {
- console.log("> Received message:", message);
-
- switch (message.type) {
- case MsgType.runScript:
- let scriptId = message.scriptId;
- const script = (await import("../" + scriptId + ".js"))?.default;
-
- if (script && isFunction(script[ClickType.onClickContentScript])) {
- script[ClickType.onClickContentScript]();
- console.log("> Run script " + scriptId);
- }
- break;
- }
- });
- } catch (e) {
- console.log("ERROR: ", e);
- }
})();
-
-// https://stackoverflow.com/a/70949953
-// https://stackoverflow.com/a/9517879
-// https://stackoverflow.com/a/2920207/11898496
-
-// https://stackoverflow.com/a/8578840/11898496
-function injectScript(
- src,
- onload,
- type = "text/javascript",
- async = false,
- defer = false
-) {
- let s = document.createElement("script");
- s.type = type;
- s.async = async;
- s.defer = defer;
- s.addEventListener("load", () => {
- console.log("Useful-scripts injected " + src);
- onload?.();
- s.remove();
- });
- s.src = src;
- let head =
- document.head ||
- document.getElementsByTagName("head")[0] ||
- document.documentElement;
- head.insertBefore(s, head.firstChild);
- // (document.head || document.documentElement).prepend(s);
-}
diff --git a/scripts/content-scripts/run_scripts.js b/scripts/content-scripts/run_scripts.js
index 746020d6..613444aa 100644
--- a/scripts/content-scripts/run_scripts.js
+++ b/scripts/content-scripts/run_scripts.js
@@ -7,36 +7,25 @@
// Kể cả việc nó đã được viết ở file khác (utils, helper, ...)
// Quá trình maintain sẽ khó hơn 1 chút, nhưng script sẽ chạy chính xác hơn
-(() => {
- // let search = new URLSearchParams(getCurrentScriptSrc().split("?")?.[1]);
- // let path = search.get("path");
-
- let { path, ids, event } = JSON.parse(
- localStorage.getItem("ufs-auto-run-scripts") ?? "{}"
- );
+(async () => {
+ let ids = [],
+ path = "";
// run script on receive event
window.addEventListener("ufs-run-page-scripts", ({ detail }) => {
- const { event, ids } = detail;
- runScripts(ids, event, path);
+ runScripts(ids, detail.event, path);
});
- // auto run initial event defined in URL search params
- if (ids && event) {
- let scriptIds = ids.split(",");
- runScripts(scriptIds, event, path);
- }
-})();
+ const data = await UsefulScriptGlobalPageContext.Extension.getActiveScripts();
+ console.log(data);
+ ids = data?.ids?.split(",") || [];
+ path = data?.path || "";
-function getCurrentScriptSrc() {
- try {
- // cannot get currentScript if script type is module: https://stackoverflow.com/a/45845801/11898496
- // return import.meta.url;
- throw false;
- } catch (e) {
- return document.currentScript.src;
+ // auto run documentStart
+ if (ids) {
+ runScripts(ids, "onDocumentStart", path);
}
-}
+})();
function runScripts(scriptIds, event, path) {
for (let id of scriptIds.filter((_) => _)) {
diff --git a/scripts/content-scripts/scripts/ufs_global_webpage_context.js b/scripts/content-scripts/scripts/ufs_global_webpage_context.js
index 4152d5e9..84f35adc 100644
--- a/scripts/content-scripts/scripts/ufs_global_webpage_context.js
+++ b/scripts/content-scripts/scripts/ufs_global_webpage_context.js
@@ -30,6 +30,11 @@ const UsefulScriptGlobalPageContext = {
);
}
},
+ getActiveScripts: async function () {
+ return await UsefulScriptGlobalPageContext.Extension.sendToContentScript(
+ "getActiveScripts"
+ );
+ },
},
DOM: {
// https://stackoverflow.com/a/3381522
diff --git a/scripts/fb_messengerCount.js b/scripts/fb_messengerCount.js
index 75fbdd09..967616fe 100644
--- a/scripts/fb_messengerCount.js
+++ b/scripts/fb_messengerCount.js
@@ -47,11 +47,7 @@ export default {
localStorage.ufs_fb_msg_kount = JSON.stringify(ranking);
- window.open(
- await UsefulScriptGlobalPageContext.Extension.getURL(
- "scripts/fb_messengerCount.html"
- )
- );
+ window.open(chrome.runtime.getURL("scripts/fb_messengerCount.html"));
} catch (e) {
alert("ERROR: " + e);
} finally {
diff --git a/scripts/fb_searchGroupForOther.js b/scripts/fb_searchGroupForOther.js
index 2216ef52..cf35f415 100644
--- a/scripts/fb_searchGroupForOther.js
+++ b/scripts/fb_searchGroupForOther.js
@@ -46,11 +46,7 @@ export default {
console.log(allGroups);
localStorage.ufs_fb_searchGroupForOther = JSON.stringify(allGroups);
localStorage.ufs_fb_searchGroupForOther_owner = JSON.stringify(info);
- window.open(
- await UsefulScriptGlobalPageContext.Extension.getURL(
- "scripts/fb_searchGroupForOther.html"
- )
- );
+ window.open(chrome.runtime.getURL("scripts/fb_searchGroupForOther.html"));
} catch (e) {
alert("ERROR: " + e);
} finally {
diff --git a/scripts/fb_searchPageForOther.js b/scripts/fb_searchPageForOther.js
index 344574a8..040101d1 100644
--- a/scripts/fb_searchPageForOther.js
+++ b/scripts/fb_searchPageForOther.js
@@ -47,11 +47,7 @@ export default {
localStorage.ufs_fb_searchPageForOther = JSON.stringify(allPages);
localStorage.ufs_fb_searchPageForOther_owner = JSON.stringify(info);
- window.open(
- await UsefulScriptGlobalPageContext.Extension.getURL(
- "scripts/fb_searchPageForOther.html"
- )
- );
+ window.open(chrome.runtime.getURL("scripts/fb_searchPageForOther.html"));
} catch (e) {
alert("ERROR: " + e);
} finally {
From 07aad60a76b872b9745e5a1f7b76e63c170fcfb4 Mon Sep 17 00:00:00 2001
From: HoangTran <99.hoangtran@gmail.com>
Date: Mon, 8 Apr 2024 02:02:44 +0700
Subject: [PATCH 3/3] fix
---
manifest.json | 39 ++++++++-----------
popup/index.js | 3 +-
popup/tabs.js | 6 +--
scripts/content-scripts/content_script.js | 6 ++-
scripts/content-scripts/document_start.js | 8 ----
.../scripts/ufs_global_webpage_context.js | 5 ---
scripts/fb_whoIsTyping.js | 2 +
working_note.md | 8 ++--
8 files changed, 32 insertions(+), 45 deletions(-)
delete mode 100644 scripts/content-scripts/document_start.js
diff --git a/manifest.json b/manifest.json
index e5178a73..1547116a 100644
--- a/manifest.json
+++ b/manifest.json
@@ -27,47 +27,40 @@
"host_permissions": [""],
"options_page": "./pages/options/options.html",
"content_scripts": [
- {
- "matches": [""],
- "js": ["scripts/content-scripts/scripts/ufs_global_webpage_context.js"],
- "run_at": "document_start",
- "world": "MAIN"
- },
- {
- "matches": [""],
- "js": ["scripts/content-scripts/scripts/ufs_global_webpage_context.js"],
- "run_at": "document_start",
- "world": "ISOLATED"
- },
{
"matches": [""],
"js": ["scripts/content-scripts/content_script.js"],
"run_at": "document_start",
- "world": "ISOLATED"
- },
- {
- "matches": [""],
- "js": ["scripts/content-scripts/run_scripts.js"],
- "run_at": "document_start",
- "world": "MAIN"
+ "world": "ISOLATED",
+ "match_origin_as_fallback": true,
+ "match_about_blank": true
},
{
"matches": [""],
- "js": ["scripts/content-scripts/document_start.js"],
+ "js": [
+ "scripts/content-scripts/scripts/ufs_global_webpage_context.js",
+ "scripts/content-scripts/run_scripts.js"
+ ],
"run_at": "document_start",
- "world": "MAIN"
+ "world": "MAIN",
+ "match_origin_as_fallback": true,
+ "match_about_blank": true
},
{
"matches": [""],
"js": ["scripts/content-scripts/document_idle.js"],
"run_at": "document_idle",
- "world": "MAIN"
+ "world": "MAIN",
+ "match_origin_as_fallback": true,
+ "match_about_blank": true
},
{
"matches": [""],
"js": ["scripts/content-scripts/document_end.js"],
"run_at": "document_end",
- "world": "MAIN"
+ "world": "MAIN",
+ "match_origin_as_fallback": true,
+ "match_about_blank": true
}
],
"web_accessible_resources": [
diff --git a/popup/index.js b/popup/index.js
index fe30f6c4..89ec98d4 100644
--- a/popup/index.js
+++ b/popup/index.js
@@ -68,8 +68,7 @@ function createTabs() {
// show scripts count
if (tab.showCount) {
let avaiCount = tab.scripts.filter((script) => !isTitle(script)).length;
- let allCount = Object.keys(allScripts).length;
- tabBtn.innerHTML += ` (${avaiCount}/${allCount})`;
+ tabBtn.innerHTML += ` (${avaiCount})`;
}
// custom style
diff --git a/popup/tabs.js b/popup/tabs.js
index 8d47207e..7916e56e 100644
--- a/popup/tabs.js
+++ b/popup/tabs.js
@@ -28,7 +28,7 @@ const tabs = [
{
...CATEGORY.search,
scripts: [
- // s._test,
+ s._test,
s.search_userscript,
s.whatFont,
s.similarWeb,
@@ -49,10 +49,10 @@ const tabs = [
...CATEGORY.download,
scripts: [
createTitle("--- All in one ---", "--- Tổng hợp ---"),
- s.savevideo_me,
+ s.vuiz_getLink,
s.saveAllVideo,
+ s.savevideo_me,
s.getLinkLuanxt,
- s.vuiz_getLink,
// s.bookmark_exporter,
s.twitter_downloadButton,
createTitle("--- Music ---", "--- Nhạc ---"),
diff --git a/scripts/content-scripts/content_script.js b/scripts/content-scripts/content_script.js
index bb55e48f..1938cf9c 100644
--- a/scripts/content-scripts/content_script.js
+++ b/scripts/content-scripts/content_script.js
@@ -1,3 +1,5 @@
+import("./scripts/ufs_global_webpage_context.js");
+
// communication between page-script and content-script
(() => {
function sendToPageScript(event, data) {
@@ -39,7 +41,9 @@
switch (message.type) {
case MsgType.runScript:
let scriptId = message.scriptId;
- const script = (await import("../" + scriptId + ".js"))?.default;
+ const script = (
+ await import(chrome.runtime.getURL("/scripts/") + scriptId + ".js")
+ )?.default;
if (script && isFunction(script[ClickType.onClickContentScript])) {
script[ClickType.onClickContentScript]();
diff --git a/scripts/content-scripts/document_start.js b/scripts/content-scripts/document_start.js
deleted file mode 100644
index 7633e835..00000000
--- a/scripts/content-scripts/document_start.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// run all scripts that has onDocumentStart event
-(async () => {
- window.dispatchEvent(
- new CustomEvent("ufs-run-page-scripts", {
- detail: { event: "onDocumentStart" },
- })
- );
-})();
diff --git a/scripts/content-scripts/scripts/ufs_global_webpage_context.js b/scripts/content-scripts/scripts/ufs_global_webpage_context.js
index 84f35adc..9746d655 100644
--- a/scripts/content-scripts/scripts/ufs_global_webpage_context.js
+++ b/scripts/content-scripts/scripts/ufs_global_webpage_context.js
@@ -1346,8 +1346,3 @@ const UsefulScriptsUtils = {
downloadData: UsefulScriptGlobalPageContext.Utils.downloadData,
};
window.UsefulScriptsUtils = UsefulScriptsUtils;
-
-// ================================= Polyfill =================================
-// Chrome pre-34
-if (!Element.prototype.matches)
- Element.prototype.matches = Element.prototype.webkitMatchesSelector;
diff --git a/scripts/fb_whoIsTyping.js b/scripts/fb_whoIsTyping.js
index 82156385..628583ab 100644
--- a/scripts/fb_whoIsTyping.js
+++ b/scripts/fb_whoIsTyping.js
@@ -20,6 +20,8 @@ export default {
websocket_instant.addEventListener("message", async function (achunk) {
let utf8_str = textDecoder.decode(achunk.data);
+ console.log(utf8_str, achunk);
+
if (
utf8_str.startsWith("1") &&
utf8_str.includes("updateTypingIndicator")
diff --git a/working_note.md b/working_note.md
index d2dff8d6..2eadddb1 100644
--- a/working_note.md
+++ b/working_note.md
@@ -20,10 +20,12 @@
- [ ] Crack tải pdf trên tailieugiangday.vn dễ vl
-- [ ] Optimize import jszip
+- [x] Optimize import jszip => có lẽ không cần
- [x] làm cho xong soundcloud_downloadMusic hoặc xóa => Xong rồi, Ngon
-- [ ] Move transfer.sh sang popup
+- [x] Move transfer.sh sang popup => Xoá luôn
-- [ ] text to qrcode không còn hoạt động
+- [x] text to qrcode không còn hoạt động => xoá luôn, ít xài
+
+- [ ] bookmark exporter/manager