-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
89 lines (75 loc) · 2.62 KB
/
main.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
var allContent = $('body');
let overlay = '<div id="quake-overlay-zzz"><button type="button" id="close-overlay">close</button><br></div>';
allContent.prepend(overlay);
function overFade() {
setTimeout(function(){ $('#quake-overlay-zzz').fadeIn(1000); }, 3000);
}
let recentGeo;
//set timeout 60s
function fetchGeo() {
fetch('https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.geojson')
.then(function(response) {
return response.json();
})
.then(function(myJson) {;
if (recentGeo === undefined) {
recentGeo = myJson.features[0];
buildInfo(recentGeo);
console.log(recentGeo.properties.mag);
//$('#quake-overlay-zzz').append('HI');
console.log(recentGeo);
}
if (JSON.stringify(myJson.features[0]) === JSON.stringify(recentGeo)) {
// shakeFunc();
console.log('nothing to report');
} else {
recentGeo = myJson.features[0];
shakeFunc();
console.log(recentGeo);
}
});
setTimeout(fetchGeo, 10000);
}
fetchGeo();
// setTimeout(fetchGeo, 60000);
function buildInfo(data) {
let mag = data.properties.mag;
let time = timeConverter(data.properties.time);
let place = data.properties.place;
$('#quake-overlay-zzz').append(`magnitude: ${mag}`);
$('#quake-overlay-zzz').append(`<br>`);
$('#quake-overlay-zzz').append(`time: ${time}`);
$('#quake-overlay-zzz').append(`<br>`);
$('#quake-overlay-zzz').append(`location: ${place}`);
}
$('#close-overlay').on('click', function() {
resetShake();
$('#quake-overlay-zzz').css('display', 'none');
});
$('span').on('click', function(e) {
console.log('pressing q', e.keyCode);
shakeFunc();
});
function shakeFunc() {
$('div').not('#quake-overlay-zzz', '.quake-info-zzz').addClass('play');
console.log('start shake');
overFade();
setTimeout(resetShake, 10000);
}
function resetShake() {
$('div').removeClass('play');
$('div').addClass('pause');
console.log('end shake');
}
function timeConverter(UNIX_timestamp){
let a = new Date(UNIX_timestamp);
let months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
let year = a.getFullYear();
let month = months[a.getMonth()];
let date = a.getDate();
let hour = a.getHours();
let min = a.getMinutes();
let sec = a.getSeconds();
let time = date + ' ' + month + ' ' + year + ' ' + hour + ':' + min + ':' + sec ;
return time;
}