This repository has been archived by the owner on Sep 7, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
49 lines (44 loc) · 1.51 KB
/
sw.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
const reportURL = 'https://reportspatrol.mineplex.com/update_punishments.php'
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
submitReport(request, sender.tab.id)
})
async function submitReport({offender, offence, category, severity, status}, tabId) {
let cookieQuery = {url: 'https://reportspatrol.mineplex.com', name: 'PHPSESSID'}
let cookie = await chrome.cookies.get(cookieQuery)
if(!cookie) {
chrome.tabs.sendMessage(tabId, {
success: false,
msg: 'No cookie found for Reports Patrol'
})
return
}
let options = {
method: 'POST',
mode: 'no-cors',
headers: {
cookie: `${cookie.name}=${cookie.value}`
},
body: new URLSearchParams({
punishment_offender: offender,
punishment_offense: offence,
punishment_category: category,
punishment_severity: severity,
punishment_status: status,
punishment_id: '',
operation: 'Add'
})
}
try {
let response = await fetch(reportURL, options)
if(!response.ok) throw new Error(response.status)
chrome.tabs.sendMessage(tabId, {
success: true,
msg: await response.text()
})
}
catch (error) {
console.log(error)
if(error.message) chrome.tabs.sendMessage(tabId, {success: false, msg: error.message})
else chrome.tabs.sendMessage(tabId, {success: false, msg: error})
}
}