Skip to content

Commit 06e8e73

Browse files
committed
lot of works
1 parent aea01f9 commit 06e8e73

18 files changed

+744
-183
lines changed

empty_script.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,15 @@ export default {
88
en: "",
99
vi: "",
1010
},
11+
12+
// Chọn 1 trong 2 cách, xoá cách không dùng:
13+
14+
// Cách 1: Mở link web trong tab mới, không cần dùng func
15+
link: "",
16+
17+
// Cách 2: Chạy script
1118
blackList: [],
1219
whiteList: [],
1320
runInExtensionContext: false,
14-
1521
func: function () {},
1622
};

manifest.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"scripting",
1919
"storage",
2020
"cookies",
21+
"debugger",
2122
"declarativeNetRequest",
2223
"declarativeNetRequestFeedback",
2324
"declarativeNetRequestWithHostAccess"

popup/helpers/scriptHelpers.js

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

popup/helpers/utils.js

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,5 @@
11
import { t } from "./lang.js";
22

3-
export const getTabId = async () => {
4-
let tabArray = await chrome.tabs.query({ currentWindow: true, active: true });
5-
return tabArray[0].id;
6-
};
7-
8-
export const runScript = async (func, tabId) => {
9-
return chrome.scripting.executeScript({
10-
target: { tabId: tabId },
11-
func: func,
12-
world: "MAIN",
13-
});
14-
};
15-
16-
export const runScriptFile = (scriptFile, tabId) => {
17-
return chrome.scripting.executeScript({
18-
target: { tabId: tabId },
19-
files: [scriptFile],
20-
world: "MAIN",
21-
});
22-
};
23-
24-
export const runScriptInCurrentTab = async (func) => {
25-
const tabId = await getTabId();
26-
return await runScript(func, tabId);
27-
};
28-
29-
export const runScriptFileInCurrentTab = async (scriptFile) => {
30-
const tabId = await getTabId();
31-
return await runScriptFile(scriptFile, tabId);
32-
};
33-
34-
export const openUrlInNewTab = async (url) => {
35-
return chrome.tabs.create({ url });
36-
};
37-
38-
export const openUrlAndRunScript = async (url, func) => {
39-
let tab = await openUrlInNewTab(url);
40-
return await runScript(func, tab.id);
41-
};
42-
43-
export async function getCurrentURL() {
44-
let tabs = await chrome.tabs.query({ active: true, currentWindow: true });
45-
return tabs[0].url;
46-
}
47-
483
export function viewScriptSource(script) {
494
localStorage.viewScriptSource_sharedData = JSON.stringify({
505
name: t(script.name),
@@ -59,4 +14,4 @@ export function viewScriptSource(script) {
5914
height: 450,
6015
width: 700,
6116
});
62-
}
17+
}

popup/index.js

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
1-
import { allScripts } from "../scripts/index.js";
2-
import { checkForUpdate } from "./helpers/checkForUpdate.js";
3-
import { getFlag, t, toggleLang } from "./helpers/lang.js";
4-
import { viewScriptSource, runScriptInCurrentTab } from "./helpers/utils.js";
51
import {
62
checkBlackWhiteList,
73
GlobalBlackList,
8-
} from "./helpers/scriptHelpers.js";
4+
isExtensionInSeperatedPopup,
5+
openExtensionInSeparatedPopup,
6+
runScriptInCurrentTab,
7+
} from "../scripts/helpers/utils.js";
8+
import { allScripts } from "../scripts/index.js";
9+
import { checkForUpdate } from "./helpers/checkForUpdate.js";
10+
import { getFlag, t, toggleLang } from "./helpers/lang.js";
911
import { openModal } from "./helpers/modal.js";
1012
import {
1113
activeTabIdSaver,
1214
favoriteScriptsSaver,
1315
recentScriptsSaver,
1416
} from "./helpers/storage.js";
17+
import { viewScriptSource } from "./helpers/utils.js";
1518
import {
1619
isFunc,
1720
isLink,
@@ -24,6 +27,7 @@ import {
2427
const tabDiv = document.querySelector("div.tab");
2528
const contentDiv = document.querySelector("div.content");
2629
const flagImg = document.querySelector("img#flag");
30+
const openInNewTabBtn = document.querySelector("#open-in-new-tab");
2731

2832
async function initLanguage() {
2933
flagImg.setAttribute("src", await getFlag());
@@ -265,7 +269,19 @@ async function runScript(script) {
265269
}
266270
}
267271

272+
function initOpenInNewTabBtn() {
273+
if (isExtensionInSeperatedPopup()) {
274+
openInNewTabBtn.remove();
275+
} else {
276+
// openInNewTabBtn.onclick = () => {
277+
openExtensionInSeparatedPopup();
278+
window.close();
279+
// };
280+
}
281+
}
282+
268283
(async function () {
284+
initOpenInNewTabBtn();
269285
await initLanguage();
270286
await createTabs();
271287
await checkForUpdate();

popup/popup.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,10 @@ <h3>
3333
<!-- language flag -->
3434
<img id="flag" src="" alt="">
3535

36+
<button id="open-in-new-tab">
37+
<i class="fa-solid fa-up-right-from-square"></i>
38+
</button>
39+
3640
<!-- modal -->
3741
<div id="myModal" class="modal">
3842
<!-- Modal content -->

popup/styles/style.css

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ a:hover {
6565
cursor: pointer;
6666
}
6767

68+
#open-in-new-tab {
69+
position: absolute;
70+
top: 0;
71+
left: 0;
72+
cursor: pointer;
73+
padding: 5px 10px;
74+
border: none;
75+
background-color: #ddd;
76+
}
77+
78+
#open-in-new-tab:hover {
79+
background-color: #bbb;
80+
}
81+
6882
#update-btn {
6983
display: none;
7084
border: none;

popup/tabs.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { allScripts as s } from "../scripts/index.js";
22
import { CATEGORY } from "./helpers/category.js";
3-
import { getAvailableScripts } from "./helpers/scriptHelpers.js";
43
import { addBadge, BADGES } from "./helpers/badge.js";
54
import { favoriteScriptsSaver, recentScriptsSaver } from "./helpers/storage.js";
5+
import { getAvailableScripts } from "../scripts/helpers/utils.js";
66

77
const createTitle = (en, vi) => ({ name: { en, vi } });
88
const isFunc = (script) => script.func && typeof script.func === "function";
@@ -60,6 +60,7 @@ const tabs = [
6060
s.zingmp3_downloadMusic,
6161
s.zingmp3_oldLayout,
6262
createTitle("--- Videos ---", "--- Video ---"),
63+
s.fb_videoDownloader,
6364
s.download_video,
6465
s.download_video2,
6566
createTitle("--- Photos ---", "--- Ảnh ---"),
@@ -104,6 +105,7 @@ const tabs = [
104105
s.fb_getAllUidFromFriendsPage,
105106
s.fb_getAllUidOfGroupMembers,
106107
createTitle("--- Download ---", "--- Tải xuống ---"),
108+
s.fb_videoDownloader,
107109
s.fb_getAvatarFromUid,
108110
s.fb_downloadCurrentVideo,
109111
s.fb_downloadAlbumMedia,
@@ -148,14 +150,16 @@ const tabs = [
148150
{
149151
...CATEGORY.automation,
150152
scripts: [
151-
s.transfer_sh,
152-
s.jsonformatter,
153153
s.textToQRCode,
154154
s.webToQRCode,
155155
s.getAllEmailsInWeb,
156+
s.screenshotFullPage,
157+
s.screenshotAreaPage,
158+
s.webToPDF,
159+
s.transfer_sh,
160+
s.jsonformatter,
156161
s.performanceAnalyzer,
157162
s.scrollToVeryEnd,
158-
s.webToPDF,
159163
],
160164
},
161165
{
@@ -188,6 +192,7 @@ const tabs = [
188192
s.scrollByDrag,
189193
s.runStatJs,
190194
createTitle("--- View ---", "--- Xem ---"),
195+
s.visualEvent,
191196
s.listAllImagesInWeb,
192197
s.viewAllLinks,
193198
s.viewScriptsUsed,

scripts/fb_videoDownloader.js

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
export default {
2+
icon: "https://www.facebook.com/favicon.ico",
3+
name: {
4+
en: "Facebook - Download video/reel/watch",
5+
vi: "Facebook - Tải video/reel/watch",
6+
},
7+
description: {
8+
en: "Download facebook video/reel/watch",
9+
vi: "Tải facebook video/reel/watch",
10+
},
11+
blackList: [],
12+
whiteList: ["https://www.facebook.com/*"],
13+
runInExtensionContext: false,
14+
15+
func: function () {
16+
// Original source code: https://gist.github.com/monokaijs/270e29620c46cabec1caca8c3746729d
17+
18+
let url = prompt("Nhập link video/reel/watch:", location.href);
19+
let videoId = url.match(/\/(?:videos|reel|watch)(?:\/?)(?:\?v=)?(\d+)/);
20+
if (!videoId || videoId.length < 2) {
21+
alert(
22+
"Link không đúng định dạng, không tìm thấy video/reel/watch id trong link."
23+
);
24+
return;
25+
}
26+
let stringifyVariables = function (d, e) {
27+
let f = [],
28+
a;
29+
for (a in d)
30+
if (d.hasOwnProperty(a)) {
31+
let g = e ? e + "[" + a + "]" : a,
32+
b = d[a];
33+
f.push(
34+
null !== b && "object" == typeof b
35+
? stringifyVariables(b, g)
36+
: encodeURIComponent(g) + "=" + encodeURIComponent(b)
37+
);
38+
}
39+
return f.join("&");
40+
},
41+
fetchGraphQl = function (doc_id, variables) {
42+
return fetch("https://www.facebook.com/api/graphql/", {
43+
method: "POST",
44+
headers: { "content-type": "application/x-www-form-urlencoded" },
45+
body: stringifyVariables({
46+
doc_id: doc_id,
47+
variables: JSON.stringify(variables),
48+
fb_dtsg: require("DTSGInitialData").token,
49+
server_timestamps: !0,
50+
}),
51+
});
52+
};
53+
54+
fetchGraphQl("5279476072161634", {
55+
UFI2CommentsProvider_commentsKey: "CometTahoeSidePaneQuery",
56+
caller: "CHANNEL_VIEW_FROM_PAGE_TIMELINE",
57+
displayCommentsContextEnableComment: null,
58+
displayCommentsContextIsAdPreview: null,
59+
displayCommentsContextIsAggregatedShare: null,
60+
displayCommentsContextIsStorySet: null,
61+
displayCommentsFeedbackContext: null,
62+
feedbackSource: 41,
63+
feedLocation: "TAHOE",
64+
focusCommentID: null,
65+
privacySelectorRenderLocation: "COMET_STREAM",
66+
renderLocation: "video_channel",
67+
scale: 1,
68+
streamChainingSection: !1,
69+
useDefaultActor: !1,
70+
videoChainingContext: null,
71+
videoID: videoId[1],
72+
})
73+
.then((res) => res.text())
74+
.then((text) => {
75+
try {
76+
let a = JSON.parse(text.split("\n")[0]),
77+
link =
78+
a.data.video.playable_url_quality_hd || a.data.video.playable_url;
79+
80+
if (link) {
81+
window.open(link);
82+
}
83+
} catch (e) {
84+
alert("Lỗi: " + e);
85+
}
86+
})
87+
.catch((e) => {
88+
alert("Lỗi: " + e);
89+
});
90+
},
91+
};

scripts/googleCache.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ export default {
2121
"Nhập URL muốn xem cache: ",
2222
url.replace(/^http\:\/\/(.*)$/, "$1")
2323
);
24-
window.open(
25-
"http://www.google.com/search?q=cache:" + encodeURIComponent(url_to_check)
26-
);
24+
if (url_to_check != null) {
25+
window.open(
26+
"http://www.google.com/search?q=cache:" +
27+
encodeURIComponent(url_to_check)
28+
);
29+
}
2730
},
2831
};

0 commit comments

Comments
 (0)