-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbackground.js
More file actions
101 lines (90 loc) · 2.93 KB
/
background.js
File metadata and controls
101 lines (90 loc) · 2.93 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var webHookUrl = "";
var username = "";
var webhook_is_valid = true;
refreshVars();
function sleep(ms) //function that allows to stop the program for a given time
{
return new Promise(resolve => setTimeout(resolve, ms));
}
function postToWebhook(content) {
var xhr = new XMLHttpRequest();
xhr.open('POST', webHookUrl, true);
xhr.setRequestHeader('Content-Type', 'application/json; charset=UTF-8');
data = {
content: content,
}
xhr.send(JSON.stringify(data));
xhr.onload = async function (res) {
console.log('posted: ', res);
if (xhr.status != 200 && xhr.status != 204 && xhr.status != 201){
console.log('Error : ', xhr.status);
if (xhr.status == 429){
var retry_after = xhr.getResponseHeader("retry-after");
console.log('Response headers = ', retry_after);
await sleep(parseInt(retry_after) + 100);
postToWebhook(content);
console.log('Resent notification after ratelimit');
}
else {
await sleep(5000);
postToWebhook(content);
console.log('Resent notification');
};
};
}
xhr.onerror = async function (res) {
console.log('error posting: ', res);
await sleep(5000);
postToWebhook(content);
console.log('Resent the notification');
}
}
chrome.runtime.onMessage.addListener(function (request, sender, sendResponse) {
sendResponse({});
if (request.type == 'update') {
refreshVars();
}
if (request.type == 'rollbit') {
postToWebhook("<@" + username + ">, Send steam offer (Rollbit)");
var options =
{
title: 'CSGOEmpire Deposit',
message: '10 minutes to send steam offer',
iconUrl: 'icons/icon_1000.png',
type: 'basic'
};
chrome.notifications.create('', options);
};
if (request.type == 'csgoempire') {
postToWebhook("<@" + username + ">, Send steam offer (CsgoEmpire)");
var options =
{
title: 'CSGOEmpire Deposit',
message: '10 minutes to send steam offer',
iconUrl: 'icons/icon_1000.png',
type: 'basic'
};
chrome.notifications.create('', options);
};
if (request.type == 'save') {
postToWebhook("<@" + username + ">, You just saved your settings on the extension.");
var options =
{
title: 'CSGOEmpire Deposit',
message: 'You hit save on the extension.',
iconUrl: 'icons/icon_1000.png',
type: 'basic'
};
chrome.notifications.create('', options);
};
});
function refreshVars() {
chrome.storage.sync.get('username', function (data) {
username = data.username;
console.log("username: " + username);
});
chrome.storage.sync.get('webHookUrl', function (data) {
webHookUrl = data.webHookUrl;
console.log("url: " + webHookUrl);
});
}