-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
utils.js
47 lines (42 loc) · 1.19 KB
/
utils.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
// Define getUserInfo function
function getUserInfo() {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage({ action: "getUserInfo" }, (response) => {
if (chrome.runtime.lastError) {
reject(chrome.runtime.lastError);
} else if (response.error) {
reject(new Error(response.error));
} else {
resolve(response.userInfo);
}
});
});
}
async function sendEventAsync(action, count) {
try {
const userInfo = await getUserInfo();
const timestamp = new Date().toISOString().replace("T", " ").substr(0, 19);
const data = {
user_id: userInfo.id || "unknown",
timestamp: timestamp,
action: action,
count: count,
};
const response = await fetch(
"https://bulk-delete-chatgpt-worker.qcrao.com/send-event",
{
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(data),
}
);
if (!response.ok) {
throw new Error(`HTTP error! status: ${response.status}`);
}
console.log(`Event '${action}' sent successfully`);
} catch (error) {
console.error(`Error sending '${action}' event:`, error);
}
}