Skip to content

Commit 7242baa

Browse files
committed
update
1 parent 7ca3b34 commit 7242baa

File tree

10 files changed

+75
-24
lines changed

10 files changed

+75
-24
lines changed

popup/helpers/checkForUpdate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export async function checkForUpdate() {
1919
en: "update v" + lastestVer,
2020
});
2121
updateBtn.onclick = () => {
22-
trackEvent("checkForUpdate");
22+
trackEvent("CHECK-FOR-UPDATE");
2323
window.open(source_code);
2424
};
2525
} else {

popup/index.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ function initLanguage() {
4040
let newLang = toggleLang();
4141
flagImg.setAttribute("src", getFlag());
4242

43-
trackEvent("change-language-" + newLang);
43+
trackEvent("CHANGE-LANGUAGE-" + newLang);
4444

4545
// reset UI
4646
createTabs();
@@ -79,6 +79,7 @@ function createTabs() {
7979
});
8080

8181
tabBtn.onclick = () => {
82+
trackEvent("OPEN-TAB-" + tab.id);
8283
openTab(tab);
8384
};
8485

@@ -245,6 +246,7 @@ function createScriptButton(script, isFavorite = false) {
245246
infoBtn.onclick = (e) => {
246247
e.stopPropagation();
247248
e.preventDefault();
249+
trackEvent(script.id + "-INFO");
248250
window.open(script.infoLink);
249251
};
250252
button.appendChild(infoBtn);
@@ -267,6 +269,7 @@ function createScriptButton(script, isFavorite = false) {
267269
addFavoriteBtn.onclick = (e) => {
268270
e.stopPropagation();
269271
e.preventDefault();
272+
trackEvent(script.id + (isFavorite ? "-REMOVE-FAVORITE" : "-ADD-FAVORITE"));
270273
favoriteScriptsSaver.toggle(script);
271274
createTabs();
272275
};
@@ -283,6 +286,7 @@ function createScriptButton(script, isFavorite = false) {
283286
e.stopPropagation();
284287
e.preventDefault();
285288

289+
trackEvent(script.id + "-VIEW-SOURCE");
286290
viewScriptSource(script);
287291
};
288292
button.appendChild(viewSourceBtn);
@@ -403,13 +407,13 @@ function initTracking() {
403407

404408
trackingEles.forEach((ele) => {
405409
ele.onclick = () => {
406-
trackEvent("click_" + ele.getAttribute("data-track"));
410+
trackEvent("CLICK_" + ele.getAttribute("data-track"));
407411
};
408412
});
409413
}
410414

411415
(async function () {
412-
trackEvent("open-popup");
416+
trackEvent("OPEN-POPUP");
413417

414418
initTracking();
415419
initSearch();

popup/tabs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ const tabs = [
7979
...CATEGORY.download,
8080
scripts: [
8181
createTitle("--- All in one ---", "--- Tổng hợp ---"),
82-
s.vuiz_getLink,
8382
s.saveAllVideo,
83+
s.vuiz_getLink,
8484
s.savevideo_me,
8585
{
8686
id: "getLinkLuanxt_newtab",

scripts/background-scripts/background-script.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const {
66
runScriptInTab,
77
getAllActiveScriptIds,
88
trackEvent,
9+
setUserId,
910
} = utils;
1011

1112
const { ISOLATED, MAIN } = chrome.scripting.ExecutionWorld;
@@ -154,7 +155,7 @@ function main() {
154155
chrome.contextMenus.onClicked.addListener((info) => {
155156
console.log(info);
156157
if (info.menuItemId == "ufs-magnify-image") {
157-
trackEvent("magnify-image-context-menu");
158+
trackEvent("magnify-image-CONTEXT-MENU");
158159
/*
159160
{
160161
"editable": false,
@@ -189,7 +190,10 @@ function main() {
189190
});
190191

191192
chrome.runtime.onInstalled.addListener(function () {
192-
GLOBAL.trackEvent("ufs-installed");
193+
GLOBAL.trackEvent("ufs-INSTALLED");
194+
195+
// create new unique id and save it
196+
setUserId();
193197

194198
chrome.contextMenus.create({
195199
title: "Magnify this image",

scripts/bookmark_exporter.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,24 @@ export default {
55
vi: "Xuất bookmarks ra file",
66
},
77
description: {
8-
en: "",
9-
vi: "",
8+
en: "Export all your browser's bookmarks to JSON file",
9+
vi: "Xuất tất cả bookmarks trong trình duyệt của bạn ra file JSON",
10+
},
11+
12+
changeLogs: {
13+
1.66: {
14+
"2024-04-27": "support download as .json",
15+
},
1016
},
1117

1218
onClickExtension: function () {
1319
chrome.bookmarks.getTree((tree) => {
1420
console.log(tree);
21+
22+
UfsGlobal.Utils.downloadData(
23+
JSON.stringify(tree, null, 4),
24+
"bookmarks.json"
25+
);
1526
});
1627
},
1728
};

scripts/helpers/utils.js

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,25 @@ const { version } =
55
? chrome.runtime.getManifest()
66
: {};
77

8+
const CACHED = {
9+
userID: null,
10+
};
11+
12+
export async function setUserId(uid = new Date().getTime()) {
13+
CACHED.userID = uid;
14+
await Storage.set("userId", uid);
15+
}
16+
17+
export async function getUserId() {
18+
if (!CACHED.userID) {
19+
CACHED.userID = await Storage.get("userId");
20+
}
21+
if (!CACHED.userID) {
22+
await setUserId();
23+
}
24+
return CACHED.userID;
25+
}
26+
827
export function waitForTabToLoad(tabId) {
928
return new Promise((resolve) => {
1029
// check if tab already loaded
@@ -71,6 +90,7 @@ export async function trackEvent(scriptId) {
7190
body: JSON.stringify({
7291
script: scriptId,
7392
version: version,
93+
uid: await getUserId(),
7494
}),
7595
}
7696
);
@@ -91,16 +111,16 @@ export async function sendEventToTab(tabId, data) {
91111
// #region Storage Utils
92112

93113
// https://developer.chrome.com/docs/extensions/reference/storage/
94-
// export const localStorage = {
95-
// set: async (key, value) => {
96-
// await chrome.storage.sync.set({ [key]: value });
97-
// return value;
98-
// },
99-
// get: async (key, defaultValue = "") => {
100-
// let result = await chrome.storage.sync.get([key]);
101-
// return result[key] || defaultValue;
102-
// },
103-
// };
114+
export const Storage = {
115+
set: async (key, value) => {
116+
await chrome.storage.local.set({ [key]: value });
117+
return value;
118+
},
119+
get: async (key, defaultValue = "") => {
120+
let result = await chrome.storage.local.get([key]);
121+
return result[key] || defaultValue;
122+
},
123+
};
104124

105125
const listActiveScriptsKey = "activeScripts";
106126
export async function setActiveScript(scriptId, isActive = true) {

scripts/insta_getAllUserMedia.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ export default {
1010
vi: "Tải về tất cả ảnh/video của người dùng instagram (sử dụng API instagram)",
1111
},
1212

13+
changeLogs: {
14+
1.66: {
15+
"2024-04-03": "optimize flow",
16+
},
17+
},
18+
1319
onClickExtension: async function () {
1420
const { downloadData } = UfsGlobal.Utils;
1521

scripts/magnify_image.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ export default {
898898
});
899899

900900
let unsub = UfsGlobal.DOM.onDoublePress("Control", () => {
901-
UfsGlobal.Extension.trackEvent("magnify-image-Ctrl");
901+
UfsGlobal.Extension.trackEvent("magnify-image-CTRL");
902902
magnifyImage(mouse.x, mouse.y);
903903
});
904904
// #endregion

scripts/saveAllVideo.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ export default {
1313
infoLink: "https://saveallvideo.net",
1414
// "https://www.facebook.com/groups/j2team.community/posts/2316412945357479/",
1515

16+
changeLogs: {
17+
1.65: {
18+
"2024-03-13": "init",
19+
},
20+
},
21+
1622
onClickExtension: async () => {
1723
const { closeLoading, setLoadingText } = showLoading(
1824
"Đang lấy thông tin tab..."

scripts/shortenURL.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,12 @@ export default {
108108
note: "cần API key",
109109
func: function (url) {
110110
return new Promise((resolve, reject) => {
111-
chrome.storage.sync.get(["cuttlyApiKey"], async function (res) {
111+
chrome.storage.local.get(["cuttlyApiKey"], async function (res) {
112112
let apiKey = res.cuttlyApiKey || "";
113113
apiKey = prompt("Enter cuttly API key:", apiKey);
114114

115115
if (apiKey) {
116-
chrome.storage.sync.set({ cuttlyApiKey: apiKey });
116+
chrome.storage.local.set({ cuttlyApiKey: apiKey });
117117
try {
118118
let longurl = encodeURIComponent(url);
119119
let resp = await fetch(
@@ -141,15 +141,15 @@ export default {
141141
note: "cần API key",
142142
func: function (url) {
143143
return new Promise((resolve, reject) => {
144-
chrome.storage.sync.get(["bitlyApiKey"], async function (res) {
144+
chrome.storage.local.get(["bitlyApiKey"], async function (res) {
145145
let apiKey = res.bitlyApiKey || "";
146146
apiKey = prompt("Enter bitly API key:", apiKey);
147147

148148
if (!apiKey) {
149149
reject("Invalid API key");
150150
}
151151

152-
chrome.storage.sync.set({ bitlyApiKey: apiKey });
152+
chrome.storage.local.set({ bitlyApiKey: apiKey });
153153
try {
154154
let longurl = encodeURIComponent(url);
155155
let resp = await fetch(

0 commit comments

Comments
 (0)