-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
63 lines (63 loc) · 2.31 KB
/
background.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
'use strict';
// background.js
chrome.runtime.onInstalled.addListener (function () {
// Check if the user is on the chat page
chrome.webNavigation.onCompleted.addListener (function (details) {
if (details.url === 'https://chat.openai.com/chat') {
// Request the activeTab permission
chrome.permissions.request (
{
permissions: ['activeTab'],
},
function (granted) {
if (granted) {
// Get the text of the page
chrome.tabs.executeScript (
{
code: 'document.body.innerText',
},
function (result) {
// Check if the text shows the high demand message
if (
result[0].includes (
"We're experiencing exceptionally high demand.",
'An error occurred. If this issue persists please contact us through our help center at help.openai.com.'
)
) {
// Request the notifications permission
chrome.permissions.request (
{
permissions: ['notifications'],
},
function (granted) {
if (granted) {
chrome.notifications.create (
{
type: 'basic',
iconUrl: 'bell-regular.svg',
title: 'ChatGPT Notifications',
message: 'Please hang tight as we work on scaling our systems.',
isClickable: true,
},
function (notificationId) {
chrome.notifications.onClicked.addListener (
function (notificationId) {
// Redirect to chat page if notification is clicked
window.location.href =
'https://chat.openai.com/chat';
}
);
}
);
}
}
);
}
}
);
}
}
);
}
});
});