Skip to content

Commit 5bc74b6

Browse files
committed
update
1 parent 2a930a1 commit 5bc74b6

File tree

11 files changed

+107
-72
lines changed

11 files changed

+107
-72
lines changed

content-scripts/document_end.js

Whitespace-only changes.

content-scripts/document_idle.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
(async () => {
2+
// const { injectScript, injectCss, baseURL } = await import("./utils.js");
3+
})();

content-scripts/document_start.js

Lines changed: 11 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,14 @@
1-
function injectScriptFile(filePathOrUrl, isExternal = false) {
2-
try {
3-
var s = document.createElement("script");
4-
s.src = isExternal ? filePathOrUrl : chrome.runtime.getURL(filePathOrUrl);
5-
s.onload = function () {
6-
console.log("Useful-scripts injected " + s.src);
7-
this.remove();
8-
};
9-
s.onerror = function (e) {
10-
console.log("ERROR: Useful-scripts inject script FAILED " + s.src, e);
11-
this.remove();
12-
};
13-
(document.head || document.documentElement).appendChild(s);
14-
} catch (e) {
15-
console.log(
16-
"ERROR: Useful-scripts inject script FAILED " + filePathOrUrl,
17-
e
18-
);
19-
}
20-
}
1+
(async () => {
2+
// https://stackoverflow.com/a/53033388
3+
const { injectScript, baseURL } = await import("./utils.js");
214

22-
const CONFIG = {
23-
enableUsefulScriptUtils: true,
24-
};
5+
// injectScript(baseURL + "track_settimeout.js");
6+
injectScript(baseURL + "globals_debugger.js");
7+
injectScript(baseURL + "useful-scripts-utils.js");
258

26-
if (CONFIG.enableUsefulScriptUtils) {
27-
// injectScriptFile("/content-scripts/track_settimeout.js");
28-
// injectScriptFile("/content-scripts/globals_debugger.js");
29-
injectScriptFile("/content-scripts/useful-scripts-utils.js");
30-
}
9+
if (location.hostname === "mp3.zing.vn")
10+
injectScript(baseURL + "mp3.zing.vn.js");
3111

32-
if (location.hostname === "mp3.zing.vn")
33-
injectScriptFile("/content-scripts/mp3.zing.vn.js");
34-
35-
// if (location.hostname === "luanxt.com")
36-
// injectScriptFile("//code.jquery.com/jquery-3.6.1.min.js", true);
12+
// if (location.hostname === "luanxt.com")
13+
// injectScriptFile("//code.jquery.com/jquery-3.6.1.min.js", true);
14+
})();

content-scripts/utils.js

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
export const baseURL = "/content-scripts/scripts/";
2+
3+
export function injectScript(filePathOrUrl, isExternal = false) {
4+
try {
5+
var s = document.createElement("script");
6+
s.src = isExternal ? filePathOrUrl : chrome.runtime.getURL(filePathOrUrl);
7+
s.onload = function () {
8+
console.log("Useful-scripts injected " + s.src);
9+
this.remove();
10+
};
11+
s.onerror = function (e) {
12+
console.log("ERROR: Useful-scripts inject script FAILED " + s.src, e);
13+
this.remove();
14+
};
15+
(document.head || document.documentElement).appendChild(s);
16+
} catch (e) {
17+
console.log(
18+
"ERROR: Useful-scripts inject script FAILED " + filePathOrUrl,
19+
e
20+
);
21+
}
22+
}
23+
24+
// https://stackoverflow.com/a/17840622
25+
export function injectCss(cssfile) {
26+
// var css = document.createElement("style");
27+
// if ("textContent" in css) css.textContent = cssText;
28+
// else css.innerText = cssText;
29+
// document.body.appendChild(css);
30+
31+
var css = document.createElement("link");
32+
css.rel = "stylesheet";
33+
css.href = chrome.runtime.getURL(cssfile);
34+
window.onload = () => {
35+
document.body.appendChild(css);
36+
console.log("Useful-scripts injected " + css.href);
37+
};
38+
}

manifest.json

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,31 @@
3535
"content-scripts/document_start.js"
3636
],
3737
"run_at": "document_start"
38+
},
39+
{
40+
"matches": [
41+
"<all_urls>"
42+
],
43+
"js": [
44+
"content-scripts/document_idle.js"
45+
],
46+
"run_at": "document_idle"
47+
},
48+
{
49+
"matches": [
50+
"<all_urls>"
51+
],
52+
"js": [
53+
"content-scripts/document_end.js"
54+
],
55+
"run_at": "document_end"
3856
}
3957
],
4058
"web_accessible_resources": [
4159
{
4260
"resources": [
43-
"content-scripts/*.js"
61+
"content-scripts/*.js",
62+
"content-scripts/*.css"
4463
],
4564
"matches": [
4665
"<all_urls>"

scripts/fb_getTokenFfb.js

Lines changed: 28 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { showLoading } from "./helpers/utils.js";
1+
import { getCookie, showLoading } from "./helpers/utils.js";
22

33
export default {
44
icon: "https://ffb.vn/assets/img/illustrations/favicon.png",
@@ -14,43 +14,33 @@ export default {
1414
whiteList: [],
1515
runInExtensionContext: true,
1616

17-
func: function () {
18-
async function getCookiesInExtensionContext(domain) {
19-
let cookies = await chrome.cookies.getAll({ domain });
20-
return cookies.map((_) => _.name + "=" + decodeURI(_.value)).join(";");
21-
}
17+
func: async function () {
18+
const { closeLoading, setLoadingText } = showLoading("Đang lấy cookie...");
19+
let cookie = await getCookie("facebook.com");
20+
if (!cookie) {
21+
alert("Không thấy cookie. Hãy chắc rằng bạn đã đăng nhập facebook!");
22+
} else {
23+
//prettier-ignore
24+
let types = ["eaaq","eaag","eaab","eaas","eaai","eaaa","Mở trang ffb.vn",];
25+
let typeIndex = prompt(
26+
"[Lưu ý]\n" +
27+
"+ Sẽ gửi cookie facebook của bạn lên ffb.vn\n" +
28+
"+ Mình không đảm bảo an toàn cho cookie của bạn\n" +
29+
"+ Ấn Cancel ngay nếu muốn huỷ\n\n" +
30+
"Chọn loại token muốn lấy:\n" +
31+
types.map((_, i) => ` ${i}: ${_.toUpperCase()}`).join("\n"),
32+
0
33+
);
2234

23-
(async () => {
24-
const { closeLoading, setLoadingText } =
25-
showLoading("Đang lấy cookie...");
26-
let cookie = await getCookiesInExtensionContext("facebook.com");
27-
if (!cookie) {
28-
alert("Không thấy cookie. Hãy chắc rằng bạn đã đăng nhập facebook!");
29-
} else {
30-
//prettier-ignore
31-
let types = ["eaaq","eaag","eaab","eaas","eaai","eaaa","Mở trang ffb.vn",];
32-
let typeIndex = prompt(
33-
"[Lưu ý]\n" +
34-
"+ Sẽ gửi cookie facebook của bạn lên ffb.vn\n" +
35-
"+ Mình không đảm bảo an toàn cho cookie của bạn\n" +
36-
"+ Ấn Cancel ngay nếu muốn huỷ\n\n" +
37-
"Chọn loại token muốn lấy:\n" +
38-
types.map((_, i) => ` ${i}: ${_.toUpperCase()}`).join("\n"),
39-
0
35+
if (typeIndex == null) {
36+
// cancel
37+
} else if (typeIndex < 0 || typeIndex >= types.length) {
38+
alert(
39+
"Invalid type. Please try again\nLựa chọn không hợp lệ. Vui lòng thử lại"
4040
);
41-
42-
if (typeIndex == null) return;
43-
if (typeIndex < 0 || typeIndex >= types.length) {
44-
alert(
45-
"Invalid type. Please try again\nLựa chọn không hợp lệ. Vui lòng thử lại"
46-
);
47-
return;
48-
}
49-
if (typeIndex == types.length - 1) {
50-
window.open("https://ffb.vn/get-token");
51-
return;
52-
}
53-
41+
} else if (typeIndex == types.length - 1) {
42+
window.open("https://ffb.vn/get-token");
43+
} else {
5444
const formData = new FormData();
5545
formData.append("cookie", cookie);
5646
formData.append("type", types[typeIndex]);
@@ -67,7 +57,7 @@ export default {
6757
prompt("Access token", json.token);
6858
}
6959
}
70-
closeLoading();
71-
})();
60+
}
61+
closeLoading();
7262
},
7363
};

scripts/helpers/utils.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,3 +54,10 @@ export function showLoading(text = "") {
5454
},
5555
};
5656
}
57+
58+
export async function getCookie(domain, raw = false) {
59+
let cookies = await chrome.cookies.getAll({ domain });
60+
return raw
61+
? cookies
62+
: cookies.map((_) => _.name + "=" + decodeURI(_.value)).join(";");
63+
}

0 commit comments

Comments
 (0)