-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathbackground.js
More file actions
28 lines (25 loc) · 1.02 KB
/
background.js
File metadata and controls
28 lines (25 loc) · 1.02 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
let timestamps = [];
let timer = null;
function startTimer() {
timer = setInterval(function() {
let cutoff = Date.now() - 3*60*60*1000;
while (timestamps.length > 0 && timestamps[0] < cutoff) {
timestamps.shift();
}
let remainingTime = timestamps.length > 0 ? Math.max(0, 3*60*60 - Math.floor((Date.now() - timestamps[0]) / 1000)) : 3*60*60;
chrome.storage.local.set({'count': timestamps.length, 'time': remainingTime});
}, 1000);
}
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.method === 'POST' && details.url.includes('https://chatgpt.com/backend-api/conversation')) {
timestamps.push(Date.now());
if (timer === null) {
startTimer();
}
let remainingTime = Math.max(0, 3*60*60 - Math.floor((Date.now() - timestamps[0]) / 1000));
chrome.storage.local.set({'count': timestamps.length, 'time': remainingTime});
}
},
{urls: ["*://chatgpt.com/*"]}
);