-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
74 lines (66 loc) · 1.8 KB
/
background.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
let fireAlretTabId = 0;
function onTabActivate(current_tab_url, tabId) {
const verifiedUrlList = [];
const scamUrlList = [];
fetch(
"https://raw.githubusercontent.com/The-Great-Ape/solana-safety-101/main/pages/api/data.json"
)
.then((response) => response.json())
.then((json) => {
json.forEach((urlGroup) =>
urlGroup.forEach((url) => {
if (url.status === "Real") {
verifiedUrlList.push(url.domain);
} else {
scamUrlList.push(url.domain);
}
})
);
}).then(() => {
verifyUrl(current_tab_url, tabId, verifiedUrlList, scamUrlList)
});
}
function verifyUrl(current_tab_url, tabId, verifiedUrlList, scamUrlList) {
const hostName = getHostNameFromUrl(current_tab_url);
if (verifiedUrlList.indexOf(hostName) > -1) {
setBadge("green", "PASS");
} else if (scamUrlList.indexOf(hostName) > -1) {
setBadge("red", "WARN");
setAlert(tabId);
} else {
setBadge("black", "UNKN");
}
}
function getHostNameFromUrl(url) {
const { hostname } = new URL(url);
return hostname;
}
function setBadge(color, text) {
chrome.action.setBadgeBackgroundColor({
color,
});
chrome.action.setBadgeText({
text,
});
}
function setAlert(tabId) {
if (fireAlretTabId != tabId) {
chrome.scripting.executeScript({
target: { tabId: tabId, allFrames: true },
func: () => alert("Warning: This website might not be an official website"),
});
fireAlretTabId = tabId;
}
}
chrome.tabs.onActivated.addListener((tab) => {
chrome.tabs.get(tab.tabId, (current_tab_info) => {
if (current_tab_info.url) {
onTabActivate(current_tab_info.url, tab.tabId);
}
});
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if (tab.url) {
onTabActivate(tab.url, tabId);
}
});