Skip to content

Commit 616ecc8

Browse files
author
hoang.tran12
committed
some fix
1 parent b3890da commit 616ecc8

File tree

10 files changed

+198
-275
lines changed

10 files changed

+198
-275
lines changed

index.html

Lines changed: 4 additions & 112 deletions
Original file line numberDiff line numberDiff line change
@@ -2,121 +2,13 @@
22
<html lang="en">
33

44
<head>
5-
<meta charset="UTF-8">
6-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7-
<title>Document</title>
5+
<meta charset="UTF-8">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Document</title>
88
</head>
99

1010
<body>
11-
12-
<script type="module">
13-
14-
const PADDING_START = "\u200c";
15-
const PADDING_END = "\u{e0061}";
16-
const CHARS = [
17-
// "\u200d",
18-
// "\u{e0061}",
19-
"\u{e0062}",
20-
"\u{e0063}",
21-
"\u{e0064}",
22-
"\u{e0065}",
23-
"\u{e0066}",
24-
"\u{e0067}",
25-
"\u{e0068}",
26-
"\u{e0069}",
27-
"\u{e006a}",
28-
"\u{e006b}",
29-
"\u{e006c}",
30-
"\u{e006d}",
31-
"\u{e006e}",
32-
"\u{e006f}",
33-
"\u{e0070}",
34-
"\u{e0071}",
35-
"\u{e0072}",
36-
"\u{e0073}",
37-
"\u{e0074}",
38-
"\u{e0075}",
39-
"\u{e0076}",
40-
"\u{e0077}",
41-
"\u{e0078}",
42-
"\u{e0079}",
43-
"\u{e007a}",
44-
"\u{e007f}",
45-
];
46-
export const shouldEncodePattern = / *>(.+?)< */;
47-
const encodedPattern = new RegExp(
48-
`${PADDING_START}([${CHARS.join("")}]+?)${PADDING_END}`
49-
);
50-
const CHARS_MAP = CHARS.reduce((curr, val, i) => {
51-
curr[val] = i;
52-
return curr;
53-
}, {});
54-
const lenCalc = (base, chars) => {
55-
var len = 0;
56-
var curr = 1;
57-
while (curr < chars) {
58-
curr *= base;
59-
len++;
60-
}
61-
return len;
62-
};
63-
const UNICODE_CHARS = 1114112;
64-
const BASE = CHARS.length;
65-
const LEN = lenCalc(BASE, UNICODE_CHARS);
66-
const charConvert = (char) => {
67-
let charCode = char.codePointAt(0);
68-
let arr = [];
69-
while (charCode > 0) {
70-
arr.push(charCode % BASE);
71-
charCode = ~~(charCode / BASE);
72-
}
73-
while (arr.length < LEN) {
74-
arr.push(0);
75-
}
76-
return arr.reverse();
77-
};
78-
const charEncode = (convertedChar) => {
79-
return convertedChar.reduce((curr, digit) => curr + CHARS[digit], "");
80-
};
81-
export const encode = (s) => {
82-
let converted = [];
83-
for (let c of s) {
84-
converted.push(charConvert(c));
85-
}
86-
let res = converted.map(charEncode);
87-
return PADDING_START + res.join("") + PADDING_END;
88-
};
89-
const decodeChar = (encodedChar) => {
90-
encodedChar = encodedChar.reverse();
91-
let curr = 1;
92-
let charCode = 0;
93-
for (let digit of encodedChar) {
94-
charCode += digit * curr;
95-
curr *= BASE;
96-
}
97-
return String.fromCodePoint(charCode);
98-
};
99-
export const decode = (s) => {
100-
s = encodedPattern.exec(s)[1];
101-
let curr = [];
102-
let res = "";
103-
for (let c of s) {
104-
curr.push(CHARS_MAP[c]);
105-
if (curr.length >= LEN) {
106-
res += decodeChar(curr);
107-
curr = [];
108-
}
109-
}
110-
return res;
111-
};
112-
export const checkEncode = (s) => {
113-
//console.log(s);
114-
return encodedPattern.exec(s);
115-
};
116-
117-
console.log(encode("abc"))
118-
119-
</script>
11+
<h1>ABC def</h1>
12012
</body>
12113

12214
</html>

manifest.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"declarativeNetRequestFeedback",
4242
"declarativeNetRequestWithHostAccess"
4343
],
44-
"host_permissions": ["<all_urls>"],
44+
"host_permissions": ["*://*/*", "<all_urls>"],
4545
"options_page": "./pages/options/options.html",
4646
"background": {
4747
"service_worker": "scripts/background-scripts/background_script.js",

popup/index.js

Lines changed: 44 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -411,7 +411,7 @@ async function updateButtonChecker(script, checkmarkContainer, val) {
411411
if (val ?? (await isActiveScript(script.id))) {
412412
checkmark.classList.add("active");
413413
tooltip = t({
414-
vi: "Tắt tự động chạy",
414+
vi: "Tắt tự chạy",
415415
en: "Turn off Autorun",
416416
});
417417
} else {
@@ -424,38 +424,48 @@ async function updateButtonChecker(script, checkmarkContainer, val) {
424424
checkmarkContainer.setAttribute("data-tooltip", tooltip);
425425
}
426426

427+
function showError(e) {
428+
Swal.fire({
429+
icon: "error",
430+
title: t({ vi: "Lỗi", en: "Error" }),
431+
text: e?.message || "",
432+
input: "textarea",
433+
inputValue: JSON.stringify(e, null, 4),
434+
});
435+
}
436+
427437
async function runScript(script) {
428438
let tab = await getCurrentTab();
429439
let willRun = checkBlackWhiteList(script, tab.url);
430440
if (willRun) {
431-
try {
432-
recentScriptsSaver.add(script);
433-
trackEvent(script.id);
441+
recentScriptsSaver.add(script);
442+
trackEvent(script.id);
434443

444+
try {
435445
if (isFunction(script.popupScript?.onClick))
436446
await script.popupScript.onClick();
437-
438-
[
439-
["MAIN", "pageScript", "onClick", false],
440-
["MAIN", "pageScript", "onClick_", true],
441-
["ISOLATED", "contentScript", "onClick", false],
442-
["ISOLATED", "contentScript", "onClick_", true],
443-
].forEach(([world, context, func, allFrames]) => {
444-
if (isFunction(script?.[context]?.[func])) {
445-
runScriptInTabWithEventChain({
446-
target: {
447-
tabId: tab.id,
448-
...(allFrames ? { allFrames: true } : {}),
449-
},
450-
scriptIds: [script.id],
451-
eventChain: context + "." + func,
452-
world: world,
453-
});
454-
}
455-
});
456447
} catch (e) {
457-
alert("ERROR: run script " + e);
448+
showError(e);
458449
}
450+
451+
[
452+
["MAIN", "pageScript", "onClick", false],
453+
["MAIN", "pageScript", "onClick_", true],
454+
["ISOLATED", "contentScript", "onClick", false],
455+
["ISOLATED", "contentScript", "onClick_", true],
456+
].forEach(([world, context, func, allFrames]) => {
457+
if (isFunction(script?.[context]?.[func])) {
458+
runScriptInTabWithEventChain({
459+
target: {
460+
tabId: tab.id,
461+
...(allFrames ? { allFrames: true } : {}),
462+
},
463+
scriptIds: [script.id],
464+
eventChain: context + "." + func,
465+
world: world,
466+
}).catch(showError);
467+
}
468+
});
459469
} else {
460470
let w = script?.whiteList?.join("<br/>");
461471
let b = script?.blackList?.join("<br/>");
@@ -596,10 +606,18 @@ function initSettings() {
596606
// smooth scroll row
597607
const smoothScrollRow = document.createElement("div");
598608
smoothScrollRow.classList.add("row");
609+
smoothScrollRow.setAttribute(
610+
"data-tooltip",
611+
t({
612+
vi: "Tắt nếu bạn đã cài app SmoothScroll",
613+
en: "Turn off if installed SmoothScroll app",
614+
})
615+
);
616+
smoothScrollRow.setAttribute("data-flow", "bottom");
599617
smoothScrollRow.innerHTML = `
600618
<div class="label">${t({
601-
vi: "Cuộn chuột mượt",
602-
en: "Smooth scroll",
619+
vi: "Cuôn chuột siêu mượt",
620+
en: "Super smooth scroll",
603621
})}</div>
604622
<div class="right-container">
605623
<button class="checkmark"></button>

popup/styles/default.less

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454

5555
* {
5656
font-family: @font_family_1;
57-
// font-weight: @font-weight;
57+
font-weight: @font-weight;
5858
margin: 0;
5959
box-sizing: border-box;
6060
color: @color_body;
@@ -523,7 +523,7 @@ option {
523523
.body {
524524
font-size: 16px;
525525
max-height: 70%;
526-
overflow: auto;
526+
// overflow: auto;
527527
}
528528
}
529529

popup/styles/xtri98.less

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
}
3535
}
3636

37-
button.tablinks {
38-
margin: 5 10 10 5;
39-
}
40-
4137
button.active {
4238
background-color: #2C7873;
4339
}
@@ -81,11 +77,6 @@
8177
}
8278
}
8379

84-
.tabcontent {
85-
border-top: none;
86-
animation: fadeEffect 0.3s;
87-
}
88-
8980
.section-title {
9081
padding: 10px 0 5px;
9182
position: sticky;

scripts/_test.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { UfsGlobal } from "./content-scripts/ufs_global.js";
2+
import { getCurrentTab } from "./helpers/utils.js";
23

34
export default {
45
icon: "",
@@ -12,6 +13,10 @@ export default {
1213
},
1314

1415
popupScript: {
16+
onClick: async () => {
17+
let currentTab = await getCurrentTab();
18+
chrome.tabs.update(currentTab.id, { url: "javascript:alert(1)" });
19+
},
1520
_onClick: async () => {
1621
const { UfsGlobal } = await import("./content-scripts/ufs_global.js");
1722
console.log(UfsGlobal);
@@ -341,7 +346,7 @@ export default {
341346

342347
pageScript: {
343348
// fb token messenger
344-
onClick: () => {
349+
_onClick: () => {
345350
let dtsg =
346351
require("DTSGInitialData").token ||
347352
document.querySelector('[name="fb_dtsg"]').value,

scripts/helpers/utils.js

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,14 @@ export const mergeObject = (...objs) => {
244244
return res;
245245
};
246246

247+
export const getAllTabs = async () => {
248+
let tabs = await chrome.tabs.query({
249+
// url: ["https://*/*", "http://*/*"],
250+
// windowType: "normal",
251+
});
252+
return tabs;
253+
};
254+
247255
// Lấy ra tab hiện tại, trong window sử dung gần nhất
248256
export const getCurrentTab = async () => {
249257
let tabs = await chrome.tabs.query({
@@ -344,8 +352,12 @@ export const runScriptInTab = async (config = {}) => {
344352
config
345353
),
346354
(injectionResults) => {
355+
if (chrome.runtime.lastError) {
356+
console.error(chrome.runtime.lastError);
357+
reject(chrome.runtime.lastError);
358+
}
347359
// https://developer.chrome.com/docs/extensions/reference/scripting/#handling-results
348-
resolve(injectionResults?.find?.((_) => _.result)?.result);
360+
else resolve(injectionResults?.find?.((_) => _.result)?.result);
349361
}
350362
);
351363
});
@@ -362,8 +374,12 @@ export const runScriptFile = (config = {}) => {
362374
config
363375
),
364376
(injectionResults) => {
377+
if (chrome.runtime.lastError) {
378+
console.error(chrome.runtime.lastError);
379+
reject(chrome.runtime.lastError);
380+
}
365381
// https://developer.chrome.com/docs/extensions/reference/scripting/#handling-results
366-
resolve(injectionResults?.find?.((_) => _.result)?.result);
382+
else resolve(injectionResults?.find?.((_) => _.result)?.result);
367383
}
368384
);
369385
});

0 commit comments

Comments
 (0)