-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
notification.js
89 lines (56 loc) · 2 KB
/
notification.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
85
86
87
88
89
//if (localStorage.getItem('news') == "") {
//
//}
//else{
//
//}
// 0 means true
// 1 means false
localStorage.setItem('notify', 0);
function notify() {
getData5();
if (localStorage.getItem('notify') == 0) {
//changing the notification icon
document.getElementById("notification").src = "assets/notification-off.svg";
//saving it in the local storage
localStorage.setItem('notify', 1);
//bringing the card down by 10vh
document.getElementById("card").style.marginTop = "25.5vh";
document.getElementById("card").style.transition = "all 0.5s ease";
} else {
//changing the notification icon
document.getElementById("notification").src = "assets/notification-light.svg";
//saving it in the local storage
localStorage.setItem('notify', 0);
//bringing the card down by 10vh
document.getElementById("card").style.marginTop = "9vh";
document.getElementById("card").style.transition = "all 0.5s ease";
}
}
// getting the latest 2 news
var api_url5 = 'https://api.covid19india.org/updatelog/log.json';
async function getData5() {
var response5 = await fetch(api_url5);
var data5 = await response5.json();
// console.log(data5);
// console.log(data5.length);
// console.log(data5[data5.length-1]);
// console.log(data5[data5.length-1].update);
console.log(data5[data5.length - 1].timestamp);
console.log(Date.now());
function Unix_timestamp(t) {
var dt = new Date(t * 1000);
var hr = dt.getHours();
var m = "0" + dt.getMinutes();
var s = "0" + dt.getSeconds();
return hr + ' : ' + m.substr(-2) + ' : ' + s.substr(-2);
}
console.log(Unix_timestamp(data5[data5.length - 1].timestamp));
var time = Unix_timestamp(data5[data5.length - 1].timestamp);
document.getElementById("news1-t").innerHTML = time;
document.getElementById("news1-c").innerHTML = (data5[data5.length - 1].update).toUpperCase();
}
getData5();
var interval5 = setInterval(function () {
getData5();
}, 60000);