-
Notifications
You must be signed in to change notification settings - Fork 0
/
background.js
84 lines (76 loc) · 2.27 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
function createNotification(id, type, title, message, buttons, iconUrl) {
if (buttons === null) {
var opt = {
type: type,
title: title,
message: message,
iconUrl: iconUrl,
};
} else {
var opt = {
type: type,
title: title,
message: message,
buttons: buttons,
iconUrl: iconUrl,
};
}
chrome.notifications.create(id, opt, function () {});
}
chrome.notifications.onButtonClicked.addListener(function (e, b) {
if (e === "notifLive") {
chrome.tabs.create({
url: "https://www.twitch.tv/jamel_le_chomeur",
});
}
chrome.notifications.clear(e);
});
const preview_url =
"https://static-cdn.jtvnw.net/previews-ttv/live_user_jamel_le_chomeur-350x200.jpg";
//var redirected = false;
var notificated = false;
const checkStatus = () => {
fetch(preview_url).then((response) => {
console.log("notificated", notificated);
if (response.redirected != true) {
/*if (redirected != true) {
redirected = true;
chrome.tabs.create({
url: "https://www.twitch.tv/jamel_le_chomeur",
});
}*/
if (notificated != true) {
createNotification(
"notifLive",
"basic",
"Jamel est en ligne !",
"Dépêchez-vous de le rejoindre !",
[
{
title: "Cliquez ici pour le rejoindre !",
},
],
"image/happy-jamel.png"
);
notificated = true;
}
}
});
};
chrome.runtime.onInstalled.addListener(() => {
createNotification(
"notifInstall",
"basic",
"Extension Jamel",
"Merci d'avoir installé l'extension 💖 !",
null,
"image/happy-jamel.png"
);
});
chrome.runtime.onStartup.addListener(() => {
checkStatus();
setInterval(checkStatus, 15 * 1000);
});
setTimeout(() => {
notificated = false;
}, 43200 * 1000);