-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathbackground.js
55 lines (45 loc) · 1.32 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
var CHANNEL_ID = 'UCv9Edl_WbtbPeURPtFDo-uA',
soundEffect = new Audio('online.mp3');
var showNotification = function() {
var time = /(..)(:..)/.exec(new Date());
var hour = time[1] % 12 || 12;
var period = time[1] < 12 ? 'AM' : 'PM';
var notification = new Notification('Live! (' + hour + time[2] + ' ' + period + ')', {
icon: 'icons/64.png',
body: 'Ice Poseidon has started streaming.',
});
if (localStorage.notificationSoundEnabled) {
var volume = (localStorage.notificationVolume / 100);
soundEffect.volume = (typeof volume == 'undefined' ? 0.50 : volume);
soundEffect.play();
}
notification.onclick = function() {
window.open('https://gaming.youtube.com/ice_poseidon/live')
}
};
var checkIfLive = function() {
if (!JSON.parse(localStorage.isActivated)) {
return;
}
$.get('http://107.170.95.160/live', function(data) {
if (data['status'] === true) {
if (JSON.parse(localStorage.isLive) === false) {
showNotification();
localStorage.isLive = true;
}
} else {
localStorage.isLive = false;
}
});
}
if (window.Notification) {
setInterval(function() {
checkIfLive();
}, 60000 * 3);
};
localStorage.isLive = false;
localStorage.isActivated = true;
localStorage.notificationSoundEnabled = true;
localStorage.notificationVolume = 50;
localStorage.isInitialized = true;
checkIfLive();