Skip to content

Commit 7ca3b34

Browse files
committed
fix a lot
1 parent 740912f commit 7ca3b34

34 files changed

+665
-331
lines changed

empty_script.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,5 @@ export default {
4444
};
4545

4646
// functions/attributes that other scripts can import and use
47+
// can only use in popup context (onClickExtension)
4748
export const shared = {};

popup/index.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ function createScriptButton(script, isFavorite = false) {
294294
if (script.description?.img) {
295295
tooltip.innerHTML += `<img src="${script.description.img}" style="width:95%" />`;
296296
}
297+
if (script.changeLogs) {
298+
let tx = "";
299+
for (let ver in script.changeLogs) {
300+
let dates = Object.keys(script.changeLogs[ver]).sort().reverse();
301+
for (let date of dates) {
302+
tx += `<li>${date} - ${script.changeLogs[ver][date]}</li>`;
303+
}
304+
}
305+
tooltip.innerHTML += `<ul class="change-logs">${tx}</ul>`;
306+
}
297307
button.appendChild(tooltip);
298308

299309
buttonContainer.appendChild(button);

popup/styles/style.css

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ a:hover {
159159
.tabcontent {
160160
padding: 6px;
161161
border-top: none;
162-
padding-bottom: 50px;
162+
padding-bottom: 300px;
163163
}
164164

165165
.tabcontent {
@@ -315,7 +315,7 @@ a:hover {
315315
min-width: 120px;
316316
background-color: rgb(133, 133, 133);
317317
color: rgb(255, 255, 255);
318-
text-align: center;
318+
text-align: left;
319319
border-radius: 6px;
320320
padding: 5px;
321321
pointer-events: none;
@@ -349,6 +349,14 @@ a:hover {
349349
border-color: transparent transparent rgb(133, 133, 133) transparent;
350350
}
351351

352+
.tooltip .tooltiptext .change-logs {
353+
border-top: 1px white solid;
354+
color: white;
355+
font-style: italic;
356+
padding: 5px;
357+
margin-top: 5px;
358+
}
359+
352360
/* --------- Modal ---------- */
353361
.modal {
354362
display: none;

popup/tabs.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ const tabs = [
202202
s.fb_getAllAlbumIdFromCurrentWebsite,
203203
s.fb_getUidFromUrl,
204204
s.fb_getAllUidFromFbSearch,
205-
s.fb_getAllUidFromFriendsPage,
206205
s.fb_getAllUidOfGroupMembers,
207206
createTitle("--- Shortcut ---", "--- Phím tắt ---"),
208207
{
@@ -259,8 +258,6 @@ const tabs = [
259258
s.insta_anonymousStoryViewer,
260259
createTitle("--- Bulk Download ---", "--- Tải hàng loạt ---"),
261260
s.insta_getAllUserMedia,
262-
s.insta_getAllImagesInUserProfile,
263-
s.insta_getAllImagesInNewFeed,
264261
],
265262
},
266263
{
@@ -305,10 +302,6 @@ const tabs = [
305302
s.douyin_downloadWachingVideo,
306303
s.douyin_downloadAllVideoUser,
307304
// s.douyin_batchDownload,
308-
s.saveAllVideo,
309-
createTitle("--- Doutu.be ---", "--- Doutu.be ---"),
310-
s.doutube_downloadWatchingVideo,
311-
s.doutube_getAllVideoInUserProfile,
312305
],
313306
},
314307
{

scripts/auto_redirectLargestImageSrc.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export default {
1010
img: "/scripts/auto_redirectLargestImageSrc.png",
1111
},
1212

13+
changeLogs: {
14+
1.66: {
15+
"2024-04-16": "init",
16+
},
17+
},
18+
1319
onDocumentStart: async () => {
1420
let oldHref = location.href;
1521
check(oldHref);

scripts/background-scripts/background-script.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,18 @@ function runScripts(tabId, event, world) {
4040

4141
async function customFetch(url, options) {
4242
try {
43+
if (
44+
typeof options?.body === "string" &&
45+
options.body.startsWith("ufs-formData:")
46+
) {
47+
let body = options.body.replace("ufs-formData:", "");
48+
body = JSON.parse(body);
49+
options.body = new FormData();
50+
for (const [key, value] of Object.entries(body)) {
51+
options.body.append(key, value);
52+
}
53+
}
54+
4355
const res = await fetch(url, options);
4456
let body;
4557

scripts/consoleLog_withTime.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ export default {
99
vi: "Hiển thị thêm thời gian chạy lệnh vào trước console.log",
1010
},
1111

12+
changeLogs: {
13+
1.66: {
14+
"2024-04-11": "init",
15+
},
16+
},
17+
1218
onDocumentStart: () => {
1319
const origLog = console.log;
1420
console.log = function () {

scripts/content-scripts/content_script.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ let utils;
55
function sendToPageScript(event, uuid, data) {
66
console.log("sendToPageScript", event, uuid, data);
77
window.dispatchEvent(
8-
new CustomEvent("ufs-contentscript-sendto-pagescript", {
9-
detail: { event, uuid, data },
8+
new CustomEvent("ufs-contentscript-sendto-pagescript" + uuid, {
9+
detail: { event, data },
1010
})
1111
);
1212
}

scripts/content-scripts/page_scripts.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
CACHED.path = path;
1717

1818
for (let id of scriptIds.filter((_) => _)) {
19-
let scriptPath = `${path}/${id}.js`;
19+
let scriptPath = `${path}${id}.js`;
2020
import(scriptPath)
2121
.then(({ default: script }) => {
2222
try {

scripts/content-scripts/ufs_global.js

Lines changed: 126 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@ UfsGlobal.Extension = {
44
// use basic customEvent technique - only communicate within the same document or window context
55
sendToContentScript(event, data) {
66
return new Promise((resolve, reject) => {
7-
let listenerKey = "ufs-contentscript-sendto-pagescript";
87
let uuid = Math.random().toString(36);
8+
let listenerKey = "ufs-contentscript-sendto-pagescript" + uuid;
99
let listener = (evt) => {
10-
if (evt.detail.event === event && evt.detail.uuid === uuid) {
11-
resolve(evt.detail.data);
12-
window.removeEventListener(listenerKey, listener);
13-
}
10+
resolve(evt.detail.data);
11+
window.removeEventListener(listenerKey, listener);
1412
};
1513
window.addEventListener(listenerKey, listener);
1614
window.dispatchEvent(
@@ -33,22 +31,21 @@ UfsGlobal.Extension = {
3331
params,
3432
});
3533
},
36-
fetchByPassOrigin(url, options = {}) {
37-
return new Promise((resolve, reject) => {
34+
async fetchByPassOrigin(url, options = {}) {
35+
try {
36+
let _url = url;
3837
let urlObject = new URL(url);
3938
// https://stackoverflow.com/a/9375786/23648002
4039
if (location.hostname == urlObject?.hostname) {
41-
url = urlObject.pathname;
40+
_url = urlObject.pathname;
4241
}
43-
fetch(url, options)
44-
.then(resolve)
45-
.catch((e) => {
46-
console.log("NORMAL FETCH FAIL: ", e);
47-
UfsGlobal.Extension.runInBackground("fetch", [url, options])
48-
.then(resolve)
49-
.catch(reject);
50-
});
51-
});
42+
let res = await fetch(_url, options);
43+
return res;
44+
} catch (e) {
45+
console.log("NORMAL FETCH FAIL: ", e);
46+
}
47+
let res = await UfsGlobal.Extension.runInBackground("fetch", [url]);
48+
return res;
5249
},
5350
getURL(filePath) {
5451
return UfsGlobal.Extension.runInContentScript("chrome.runtime.getURL", [
@@ -70,6 +67,18 @@ UfsGlobal.Extension = {
7067
},
7168
};
7269
UfsGlobal.DOM = {
70+
closest(element, selector) {
71+
let el = element;
72+
while (el !== null) {
73+
if (el.matches(selector)) return el;
74+
75+
let found = el.querySelector(selector);
76+
if (found) return found;
77+
78+
el = el.parentElement;
79+
}
80+
return el;
81+
},
7382
addLoadingAnimationAtPos(
7483
x,
7584
y,
@@ -554,6 +563,39 @@ UfsGlobal.DOM = {
554563
},
555564
};
556565
UfsGlobal.Utils = {
566+
async json2xml(json) {
567+
if (!window.json2xml) {
568+
let url = await UfsGlobal.Extension.getURL(
569+
"/scripts/libs/xml-json/json2xml.js"
570+
);
571+
await UfsGlobal.DOM.injectScriptSrcAsync(url);
572+
}
573+
return window.json2xml(json);
574+
},
575+
async xml2json(xml) {
576+
if (!window.xml2json) {
577+
let url = await UfsGlobal.Extension.getURL(
578+
"/scripts/libs/xml-json/xml2json.js"
579+
);
580+
await UfsGlobal.DOM.injectScriptSrcAsync(url);
581+
}
582+
return window.xml2json(xml);
583+
},
584+
getLargestSrcset(srcset) {
585+
var srcs = srcset.split(/[xw],/i),
586+
largeSize = -1,
587+
largeSrc = null;
588+
if (!srcs.length) return null;
589+
srcs.forEach((srci) => {
590+
let srcInfo = srci.trim().split(/(\s+|%20)/),
591+
curSize = parseInt(srcInfo[2] || 0);
592+
if (srcInfo[0] && curSize > largeSize) {
593+
largeSize = curSize;
594+
largeSrc = srcInfo[0];
595+
}
596+
});
597+
return largeSrc;
598+
},
557599
svgBase64ToUrl(sgvBase64) {
558600
try {
559601
if (!/^data:image\/svg/.test(sgvBase64)) throw new Error("Invalid SVG");
@@ -1903,8 +1945,11 @@ UfsGlobal.Tiktok = {
19031945
const params = Object.keys(parameters)
19041946
.map((key) => `&${key}=${parameters[key]}`)
19051947
.join("");
1906-
let data = await fetch(api + videoId + "&" + params);
1907-
let json = await data.json();
1948+
let data = await UfsGlobal.Extension.runInBackground("fetch", [
1949+
api + videoId + "&" + params,
1950+
]);
1951+
console.log(data);
1952+
let json = JSON.parse(data.body);
19081953
console.log(json);
19091954
let item = json.aweme_list.find((a) => a.aweme_id == videoId);
19101955
if (!item) throw Error("Không tìm thấy video");
@@ -1921,35 +1966,60 @@ UfsGlobal.Tiktok = {
19211966
CACHE: {
19221967
snapTikToken: null,
19231968
},
1924-
downloadTiktokVideoFromUrl: async function (url) {
1969+
downloadTiktokVideoFromUrl: async function (url, background = false) {
19251970
try {
19261971
let token = UfsGlobal.Tiktok.CACHE.snapTikToken;
19271972
if (!token) {
1928-
let token = await UfsGlobal.SnapTik.getToken();
1973+
let token = await UfsGlobal.SnapTik.getToken(background);
19291974
if (!token) throw Error("Không tìm thấy token snaptik");
19301975
UfsGlobal.Tiktok.CACHE.snapTikToken = token;
19311976
}
19321977

1933-
let data = new FormData();
1934-
data.append("url", url);
1935-
data.append("token", token);
1936-
1937-
let res = await fetch("https://snaptik.app/abc2.php", {
1938-
method: "POST",
1939-
body: data,
1940-
});
1941-
let text = await res.text();
1978+
let form = new FormData();
1979+
form.append("url", url);
1980+
form.append("token", token);
1981+
1982+
let text;
1983+
if (background) {
1984+
let res = await UfsGlobal.Extension.runInBackground("fetch", [
1985+
"https://snaptik.app/abc2.php",
1986+
{
1987+
method: "POST",
1988+
body:
1989+
"ufs-formData:" +
1990+
JSON.stringify({
1991+
url: url,
1992+
token: token,
1993+
}),
1994+
},
1995+
]);
1996+
text = res.body;
1997+
} else {
1998+
let res = await fetch("https://snaptik.app/abc2.php", {
1999+
method: "POST",
2000+
body: form,
2001+
});
2002+
text = await res.text();
2003+
}
19422004
let result = UfsGlobal.SnapTik.decode(text);
19432005
return result;
19442006
} catch (e) {
1945-
console.log("ERROR: " + e);
2007+
console.log("ERROR: ", e);
19462008
}
19472009
},
19482010
};
19492011
UfsGlobal.SnapTik = {
1950-
getToken: async () => {
1951-
let res = await fetch("https://snaptik.app/");
1952-
let text = await res.text();
2012+
getToken: async (background = false) => {
2013+
let text;
2014+
if (background) {
2015+
let res = await UfsGlobal.Extension.runInBackground("fetch", [
2016+
"https://snaptik.app/",
2017+
]);
2018+
text = res.body;
2019+
} else {
2020+
let res = await fetch("https://snaptik.app/");
2021+
text = await res.text();
2022+
}
19532023
let token = text.match(/name="token" value="(.+?)"/)?.[1];
19542024
return token;
19552025
},
@@ -1998,6 +2068,7 @@ UfsGlobal.SnapTik = {
19982068

19992069
let result = c(...params);
20002070
let jwt = result.match(/d\?token=(.*?)\&dl=1/)?.[1];
2071+
if (!jwt) return null;
20012072
let payload = UfsGlobal.Utils.parseJwt(jwt);
20022073
return payload?.url;
20032074
},
@@ -2731,11 +2802,27 @@ UfsGlobal.largeImgSiteRules = [
27312802
},
27322803
];
27332804

2734-
if (window) window.UfsGlobal = UfsGlobal;
2735-
27362805
// export if posible
2737-
if (typeof module !== "undefined" && typeof module.exports !== "undefined") {
2738-
module.exports = UfsGlobal;
2739-
}
2806+
(function (f) {
2807+
if (typeof exports === "object" && typeof module !== "undefined") {
2808+
module.exports = f();
2809+
} else if (typeof define === "function" && define.amd) {
2810+
define([], f);
2811+
} else {
2812+
var g;
2813+
if (typeof window !== "undefined") {
2814+
g = window;
2815+
} else if (typeof global !== "undefined") {
2816+
g = global;
2817+
} else if (typeof self !== "undefined") {
2818+
g = self;
2819+
} else {
2820+
g = this;
2821+
}
2822+
g.UfsGlobal = f();
2823+
}
2824+
})(function () {
2825+
return UfsGlobal;
2826+
});
27402827

27412828
console.log("UfsGlobal loaded");

0 commit comments

Comments
 (0)