-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathbroker.js
More file actions
43 lines (41 loc) · 1.78 KB
/
broker.js
File metadata and controls
43 lines (41 loc) · 1.78 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
chrome.storage.local.get(({ settings }) => {
sendPayload({
action: 'setStorage',
storage: settings
})
});
chrome.storage.local.onChanged.addListener(({ settings }) => {
settings && sendPayload({
action: 'updateStorage',
storage: settings.newValue
})
});
function sendPayload(data) {
return postMessage(Object.assign({ sender: 'frhd-lite' }, data))
}
(webhook => {
addEventListener('message', ({ data }) => {
switch(data.action) {
case 'report':
let url = 'http://frhd.co/';
let content = '';
data.type !== 'user' && (data.type === 'race' && (content += '[Race](<' + url + 't/' + data.data.t_id + '/r/' + (data.data.u_name || data.data.d_name.toLowerCase()) + '>) by [' + data.data.d_name + '](<' + url + 'u/' + (data.data.u_name || data.data.d_name.toLowerCase()) + '>) on '),
data.data.t_id && (content += '[' + (data.type === 'race' ? 't' : 'T') + 'rack](<' + url + 't/' + data.data.t_id + '>)'),
data.type === 'leaderboard' && (content += ' leaderboard'));
data.type === 'user' && (content += 'User [' + data.data.d_name + '](<' + url + 'u/' + data.data.d_name + '>)');
fetch('https://discord.com/api/webhooks/' + webhook.id + '/' + webhook.secret, {
body: JSON.stringify({
content: content + ' was reported by [' + data.reporter.d_name + '](<' + url + 'u/' + data.reporter.u_name + '>).'
}),
headers: { 'Content-Type': 'application/json' },
method: 'POST'
}).then(r => r.text())
// navigator.sendBeacon('https://discord.com/api/webhooks/' + webhook.id + '/' + webhook.secret, new URLSearchParams({
// content: content + ' was reported by [' + data.reporter.d_name + '](<' + url + 'u/' + data.reporter.u_name + '>).'
// }))
}
})
})({
id: '1254881864557264957',
secret: 'XQ-9eJh-fxHfn3jgbozovFcHQVhk601Z1-Hks4UWKFKtx2CrNnk7KhlxH1Je-5T-_xVT'
})