Skip to content

Commit a467c78

Browse files
committed
little refactor
1 parent ee95c43 commit a467c78

File tree

6 files changed

+42
-21
lines changed

6 files changed

+42
-21
lines changed

popup/helpers/utils.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ export const canAutoRun = (script) => {
2929
"onClick",
3030
"onInstalled",
3131
"onStartup",
32+
"onMessage",
3233
"contextMenus",
3334
]);
3435
for (let context of CONTEXTS) {

popup/tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ const tabs = [
247247
},
248248
description: {
249249
en: "Very good Bookmark manager, find your bookmarks faster.",
250-
vi: "Trình quản lý extension ngon, tìm kiếm bookmark nhanh hơn bao giờ hết.",
250+
vi: "Trình quản lý bookmark ngon, tìm kiếm bookmark nhanh hơn bao giờ hết.",
251251
},
252252
popupScript: {
253253
onClick: () =>

scripts/background-scripts/background_script.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,8 @@ function listenMessage() {
388388
// tabId: sender.tab.id,
389389
// frameIds: [sender.frameId],
390390
// },
391-
{ request, sender, sendResponse: internalSendEvent }
391+
{ request, sender, sendResponse: internalSendEvent },
392+
true
392393
);
393394
return sended ? false : true;
394395
}

scripts/ggdrive_downloadPresentation.js

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,34 +13,50 @@ export default {
1313

1414
popupScript: {
1515
onClick: async () => {
16-
const { getCurrentTab } = await import("./helpers/utils.js");
16+
const { t } = await import("../popup/helpers/lang.js");
17+
const { getCurrentTab, openWebAndRunScript } = await import(
18+
"./helpers/utils.js"
19+
);
1720
let tab = await getCurrentTab();
1821
let { url, title } = tab;
1922

23+
let guide = t({
24+
vi: "Sử dụng chức năng\nTự động > In web ra PDF hoặc\nTự động > Chụp ảnh toàn bộ web\nđể tải slides nhé.",
25+
en: "Please use feature\nAutomation > Screenshot full page OR\nAutomation > Web to PDF\nto download this slides",
26+
});
27+
2028
if (url.includes("/htmlpresent")) {
21-
alert(
22-
"Ban hãy bấm Ctrl+S để lưu toàn bộ slides trong trang hiện tại nhé."
23-
);
29+
alert(guide);
2430
} else {
2531
url = prompt(
26-
"Nhập link file powerpoint (slide) google drive: \nĐịnh dạng: https://docs.google.com/presentation/*",
32+
t({
33+
vi: "Nhập link file powerpoint (slide) google drive: \nĐịnh dạng: https://docs.google.com/presentation/*",
34+
en: "Enter google drive presentation url: \nFormat: https://docs.google.com/presentation/*",
35+
}),
2736
url
2837
);
2938
if (!url) return;
3039

3140
let id = /d\/([^\/]+)\/?/.exec(url)?.[1];
3241
if (!id) {
33-
alert("Không tìm được id file trên url");
42+
alert(
43+
t({
44+
vi: "Không tìm được id file trên url",
45+
en: "Can not find file id in url",
46+
})
47+
);
3448
return;
3549
}
3650

37-
alert(
38-
"File sẽ được mở trong trang mới. Bạn có thể bấm Ctrl+S để lưu toàn bộ slides trong trang mới."
39-
);
40-
41-
window.open(
42-
"https://docs.google.com/presentation/d/" + id + "/htmlpresent"
43-
);
51+
openWebAndRunScript({
52+
url: "https://docs.google.com/presentation/d/" + id + "/htmlpresent",
53+
func: async (guide) => {
54+
window.onload = alert(guide);
55+
},
56+
args: [guide],
57+
focusImmediately: true,
58+
waitUntilLoadEnd: false,
59+
});
4460
}
4561
},
4662
},

scripts/helpers/utils.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,10 @@ export function closeTab(tab) {
278278
return chrome.tabs.remove(tab.id);
279279
}
280280

281+
export function pinTab(tab, pinned = true) {
282+
return chrome.tabs.update(tab.id, { pinned: pinned });
283+
}
284+
281285
export const runScriptInTabWithEventChain = ({
282286
target,
283287
scriptIds,
@@ -387,6 +391,8 @@ export const runScriptFileInCurrentTab = async (scriptFile, world = "MAIN") => {
387391
};
388392

389393
// https://stackoverflow.com/a/68634884/11898496
394+
// WARNING: should be run in backgound script
395+
// If use this in popup script, when tab is focus, popup page will be closed => script not finish
390396
export async function openWebAndRunScript({
391397
url,
392398
func,
@@ -397,9 +403,8 @@ export async function openWebAndRunScript({
397403
closeAfterRunScript = false,
398404
focusImmediately = false,
399405
}) {
400-
let tab = await chrome.tabs.create({ active: false, url: url });
406+
let tab = await chrome.tabs.create({ active: focusImmediately, url: url });
401407
if (waitUntilLoadEnd) await waitForTabToLoad(tab.id);
402-
if (focusImmediately) focusToTab(tab);
403408
let res = await runScriptInTab({
404409
func,
405410
target: { tabId: tab.id },

scripts/prevent_closeBrowser_lastTab.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,9 @@ export default {
66
},
77
description: {
88
en: `Prevent closing of Browser after close the last tab<br/>
9-
Auto create new empty tab if no tab left<br/>
10-
(only if last tab is not empty tab)`,
9+
Auto create new empty tab if no tab left`,
1110
vi: `Không tắt trình duyệt khi tắt tab cuối cùng<br/>
12-
Tự động mở tab mới khi bạn tắt tab cuối cùng<br/>
13-
(chỉ chạy nếu tab cuối cùng bạn tắt không phải tab trống)`,
11+
Tự động mở tab mới khi bạn tắt tab cuối cùng`,
1412
img: "",
1513
},
1614

0 commit comments

Comments
 (0)