Skip to content

Commit 92cb54c

Browse files
author
hoang.tran12
committed
fix chongLuaDao
1 parent 8792cb6 commit 92cb54c

File tree

6 files changed

+639
-304
lines changed

6 files changed

+639
-304
lines changed

scripts/_test.js

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export default {
1010
},
1111

1212
popupScript: {
13-
onClick: async () => {
13+
_onClick: async () => {
1414
const { openWebAndRunScript } = await import("./helpers/utils.js");
1515
openWebAndRunScript({
1616
url: "https://www.whitescreen.online/blue-screen-of-death-windows/",
@@ -150,6 +150,43 @@ export default {
150150
},
151151

152152
contentScript: {
153+
onClick: () => {
154+
function formatSize(size, fixed = 0) {
155+
size = Number(size);
156+
if (!size) return "?";
157+
158+
const units = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
159+
let unitIndex = 0;
160+
while (size >= 1024 && unitIndex < units.length - 1) {
161+
size /= 1024;
162+
unitIndex++;
163+
}
164+
return size.toFixed(fixed) + units[unitIndex];
165+
}
166+
167+
// https://stackoverflow.com/a/23329386
168+
function byteLength(str) {
169+
// returns the byte length of an utf8 string
170+
var s = str.length;
171+
for (var i = str.length - 1; i >= 0; i--) {
172+
var code = str.charCodeAt(i);
173+
if (code > 0x7f && code <= 0x7ff) s++;
174+
else if (code > 0x7ff && code <= 0xffff) s += 2;
175+
if (code >= 0xdc00 && code <= 0xdfff) i--; //trail surrogate
176+
}
177+
return s;
178+
}
179+
180+
try {
181+
let text = document.body.innerText;
182+
let len = text.length;
183+
let size = byteLength(text);
184+
size = formatSize(size, 1);
185+
alert("Text in this website: " + len + " characters (" + size + ")");
186+
} catch (e) {
187+
alert(e);
188+
}
189+
},
153190
_onClick: () => {
154191
function analyzeWebpage() {
155192
const href = window.location.href,

scripts/backup/chongLuaDao_bg.js

Lines changed: 246 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,246 @@
1+
! function(e) {
2+
var t = {};
3+
function n(i) {
4+
if (t[i]) return t[i].exports;
5+
var r = t[i] = {
6+
i: i,
7+
l: !1,
8+
exports: {}
9+
};
10+
return e[i].call(r.exports, r, r.exports, n), r.l = !0, r.exports
11+
}
12+
n.m = e, n.c = t, n.d = function(e, t, i) {
13+
n.o(e, t) || Object.defineProperty(e, t, {
14+
enumerable: !0,
15+
get: i
16+
})
17+
}, n.r = function(e) {
18+
"undefined" != typeof Symbol && Symbol.toStringTag && Object.defineProperty(e, Symbol.toStringTag, {
19+
value: "Module"
20+
}), Object.defineProperty(e, "__esModule", {
21+
value: !0
22+
})
23+
}, n.t = function(e, t) {
24+
if (1 & t && (e = n(e)), 8 & t) return e;
25+
if (4 & t && "object" == typeof e && e && e.__esModule) return e;
26+
var i = Object.create(null);
27+
if (n.r(i), Object.defineProperty(i, "default", {
28+
enumerable: !0,
29+
value: e
30+
}), 2 & t && "string" != typeof e)
31+
for (var r in e) n.d(i, r, function(t) {
32+
return e[t]
33+
}.bind(null, r));
34+
return i
35+
}, n.n = function(e) {
36+
var t = e && e.__esModule ? function() {
37+
return e.default
38+
} : function() {
39+
return e
40+
};
41+
return n.d(t, "a", t), t
42+
}, n.o = function(e, t) {
43+
return Object.prototype.hasOwnProperty.call(e, t)
44+
}, n.p = "", n(n.s = 0)
45+
}([function(e, t) {
46+
window.isWhiteList = {}, window.isBlocked = {}, window.results = {}, window.isPhish = {}, window.legitimatePercents = {};
47+
let blackList = [];
48+
const whiteList = [];
49+
let r = !1;
50+
const o = e => {
51+
chrome.storage.local.get(["cache", "cacheTime"], t => {
52+
if (t.cache && t.cacheTime) return e(t.cache);
53+
(e => {
54+
fetch("https://api.chongluadao.vn/classifier.json")
55+
.then(e => e.json())
56+
.then(t => {
57+
chrome.storage.local.set({
58+
cache: t,
59+
cacheTime: Date.now()
60+
}, () => e(t))
61+
})
62+
})(e)
63+
})
64+
},
65+
s = (e, t, n) => {
66+
if (window.isWhiteList[e] == n) return;
67+
let i = 0,
68+
r = 0,
69+
s = 0;
70+
for (const e in t) "1" == t[e] ? s++ : "0" == t[e] ? r++ : i++;
71+
if (window.legitimatePercents[e] = i / (s + r + i) * 100, t.length) {
72+
const n = [t.map(e => parseInt(e))];
73+
o((function(t) {
74+
const i = (e => ({
75+
predict: t => {
76+
let n = [e.estimators.map(e => (e => {
77+
const t = t => {
78+
let n = e;
79+
for (;
80+
"split" == n.type;) {
81+
const e = n.threshold.split(" <= ");
82+
n = t[e[0]] <= e[1] ? n.left : n.right
83+
}
84+
return n.value[0]
85+
};
86+
return {
87+
predict: e => e.map(e => t(e)),
88+
predictOne: t
89+
}
90+
})(e)
91+
.predict(t))];
92+
n = n[0].map((e, t) => n.map(e => e[t]));
93+
const i = [];
94+
for (const e in n) {
95+
let t = 0,
96+
r = 0;
97+
for (const i in n[e]) t += n[e][i][1], r += n[e][i][0];
98+
i.push([t >= r, Math.max(t, r)])
99+
}
100+
return i
101+
}
102+
}))(t);
103+
window.isPhish[e] = i.predict(n)[0][0], window.isPhish[e] && window.legitimatePercents[e] > 60 && (window.isPhish[e] = !1), l(window.isPhish[e], window.legitimatePercents[e], e)
104+
}))
105+
}
106+
},
107+
c = () => {
108+
fetch("https://api.chongluadao.vn/v2/blacklist")
109+
.then(e => e.json())
110+
.then(e => {
111+
e.forEach(e => {
112+
blackList.push(e.url)
113+
})
114+
})
115+
.catch(() => {}), fetch("https://api.chongluadao.vn/v2/whitelist")
116+
.then(e => e.json())
117+
.then(e => {
118+
e.forEach(e => {
119+
whiteList.push(e.url)
120+
})
121+
})
122+
.catch(() => {})
123+
},
124+
redirectToBlocking = (e, t, n) => {
125+
const i = {
126+
site: e,
127+
match: t,
128+
title: e,
129+
lenient: r,
130+
favicon: "https://www.google.com/s2/favicons?domain=" + e
131+
};
132+
window.isBlocked[n] = e, chrome.browserAction.setIcon({
133+
path: "../assets/cldvn_red.png",
134+
tabId: n
135+
});
136+
return {
137+
redirectUrl: `${chrome.extension.getURL("blocking.html")}#${JSON.stringify(i)}`
138+
}
139+
},
140+
makeURL = e => {
141+
try {
142+
return new URL(e)
143+
} catch (e) {
144+
return
145+
}
146+
},
147+
l = (e, t, n) => {
148+
if (chrome.browserAction.setTitle({
149+
title: `P:${e} per: ${t}`
150+
}), e) return chrome.browserAction.setIcon({
151+
path: "../assets/cldvn_red.png",
152+
tabId: n
153+
});
154+
chrome.browserAction.setIcon({
155+
path: "../assets/cldvn128.png",
156+
tabId: n
157+
})
158+
},
159+
getHost = e => {
160+
const t = e.match(/^https?:\/\/([^/?#]+)(?:[/?#]|$)/i);
161+
return t && t[1]
162+
};
163+
chrome.runtime.onStartup.addListener(c), chrome.runtime.onInstalled.addListener(() => {
164+
c(), chrome.notifications.create({
165+
type: "basic",
166+
iconUrl: chrome.extension.getURL("assets/logo.png"),
167+
title: "Cài đặt thành công!",
168+
message: "Khởi động lại trình duyệt của bạn để có thể bắt đầu sử dụng ChongLuaDao. Xin cảm ơn!"
169+
})
170+
}), chrome.tabs.onActivated.addListener((e = null) => {
171+
if (e && e.tabId) return l(window.isPhish[e.tabId], window.legitimatePercents[e.tabId], e.tabId);
172+
chrome.tabs.query({
173+
active: !0,
174+
currentWindow: !0
175+
}, ([e]) => {
176+
l(window.isPhish[e.id], window.legitimatePercents[e.id], e.id)
177+
})
178+
}), chrome.tabs.onUpdated.addListener((e, t, n) => {
179+
"complete" == n.status && chrome.tabs.sendMessage(n.id, n)
180+
}), chrome.runtime.onConnect.addListener(e => {
181+
switch (e.name) {
182+
case "REDIRECT_PORT_NAME":
183+
e.onMessage.addListener(e => {
184+
chrome.tabs.query({
185+
currentWindow: !0,
186+
active: !0
187+
}, ([t]) => {
188+
chrome.tabs.update(t.id, {
189+
url: e.redirect
190+
})
191+
})
192+
});
193+
break;
194+
case "CLOSE_TAB_PORT_NAME":
195+
e.onMessage.addListener(e => {
196+
e.close_tab && chrome.tabs.query({
197+
currentWindow: !0,
198+
active: !0
199+
}, ([e]) => {
200+
chrome.tabs.remove(e.id)
201+
})
202+
});
203+
break;
204+
case "ML_PORT_NAME":
205+
e.onMessage.addListener(e => {
206+
const {
207+
request: t
208+
} = e;
209+
void 0 !== t.input_block_list && (blackList = t.input_block_list, r = t.input_block_lenient), chrome.tabs.query({
210+
currentWindow: !0,
211+
active: !0
212+
}, ([e]) => {
213+
window.results[e.id] = t, s(e.id, t, e.url)
214+
})
215+
})
216+
}
217+
}), chrome.webRequest.onBeforeRequest.addListener(({
218+
url: url,
219+
tabId: tabId,
220+
initiator: initiator
221+
}) => {
222+
if (!url || 0 === url.indexOf("chrome://") || 0 === url.indexOf(chrome.extension.getURL("/"))) return;
223+
if (!blackList || !blackList.length) return;
224+
if (localStorage.getItem("whiteList")) return localStorage.removeItem("whiteList");
225+
const _blackList = blackList,
226+
_url = makeURL(url),
227+
psl_res = psl.parse(_url.host),
228+
l = _url.href.replaceAll("/", "");
229+
for (let n = 0; n < _blackList.length; ++n) {
230+
const black_url = makeURL(_blackList[n]);
231+
if (!black_url) continue;
232+
const firstPart = black_url.host.split(".")[0],
233+
pathName = black_url.pathname;
234+
if ("%2A" == firstPart) {
235+
if (black_url.host.slice(4, black_url.host.length) == psl_res.domain) return redirectToBlocking(url, black_url.host, tabId)
236+
}
237+
if ("/*" == pathName && _url.host === black_url.host) return redirectToBlocking(url, black_url.host, tabId);
238+
if (l && l == black_url.href.replaceAll("/", "")) return redirectToBlocking(url, black_url.host, tabId)
239+
}
240+
const hostName = getHost(initiator || url);
241+
whiteList.find(e => e.includes(hostName)) && (window.isWhiteList[tabId] = hostName)
242+
}, {
243+
urls: ["*://*/*"],
244+
types: ["main_frame", "sub_frame"]
245+
}, ["blocking"])
246+
}]);

0 commit comments

Comments
 (0)