-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
79 lines (67 loc) · 2.5 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
75
76
77
78
79
let config = {
url: 'https://browsermate.herokuapp.com/request',
// url: 'http://d838-77-111-227-3.ngrok.io/request'
};
let options = {
name: "Ryan",
message: "%name% is accessing content that they shouldn't be. %link%",
formatted_message: "Ryan is accessing content that they shouldn't be.",
number: "+447579065474",
agreed: true,
tracked_websites: [
"https://www.youtube.com/",
"https://twitter.com/",
"https://www.facebook.com/",
"https://www.twitch.tv/"
]
}
function isBlocked(url, blocked_sites) {
for (let blocked_site of blocked_sites) {
if (url.startsWith(blocked_site)) {
return true;
}
}
return false;
}
chrome.tabs.onUpdated.addListener(function (tabId, info, tab) {
// chrome.storage.sync.get(['username'], function(result) {
// console.log('Value currently is ' + result.key);
// alert(result.key);
// });
// if (!options.agreed) return;
if (info.status != 'complete') return;
let url = tab.url; // get the URL of the currently open tab
if (url.startsWith("chrome://")) return;
if (!isBlocked(url, options.tracked_websites)) return;
postData(config.url, {
url: url,
message: options.formatted_message + url,
username: name,
number: "+447579065474"
}).then().catch(e => console.log(e));
});
function check_if_bad(html) {
if (html.includes("roblox")) {
return true;
} else {
return false;
}
}
// function to post data to an endpoint thanks stackoverflow xoxoxo
async function postData(url = '', data = {}) {
// Default options are marked with *
const response = await fetch(url, {
method: 'POST', // *GET, POST, PUT, DELETE, etc.
mode: 'cors', // no-cors, *cors, same-origin
cache: 'no-cache', // *default, no-cache, reload, force-cache, only-if-cached
credentials: 'same-origin', // include, *same-origin, omit
headers: {
'Content-Type': 'application/json'
// 'Content-Type': 'application/x-www-form-urlencoded',
},
redirect: 'follow', // manual, *follow, error
referrerPolicy: 'no-referrer', // no-referrer, *no-referrer-when-downgrade, origin, origin-when-cross-origin, same-origin, strict-origin, strict-origin-when-cross-origin, unsafe-url
body: JSON.stringify(data) // body data type must match "Content-Type" header
});
return response.json(); // parses JSON response into native JavaScript objects
};