-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (37 loc) · 1.2 KB
/
index.js
File metadata and controls
45 lines (37 loc) · 1.2 KB
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
// Settings
// App ID
const appId = '626776655';
// Store Country
const country = 'jp';
// Check Interval
const checkInterval = 1000;
const fetchUrl = 'http://ax.itunes.apple.com/WebObjects/MZStoreServices.woa/wa/wsSearch?country=' + country + '&entity=software&term=' + appId
const http = require('http');
var latestVersion = '';
var msg = '';
setInterval(function(){
const dt = new Date();
const now = padding2(dt.getHours()) + ':' + padding2(dt.getMinutes()) + ':' + padding2(dt.getSeconds());
http.get(fetchUrl, function(res){
let data = '';
res.on('data', function(c){data += c;});
res.on('end', function(){
res = JSON.parse(data);
if(res.results[0].version != latestVersion) {
latestVersion = res.results[0].version;
msg = 'Version: ' + latestVersion;
process.stdout.write('\n[' + now + '] ' + msg);
} else {
process.stdout.write('\r[' + now + '] ' + msg);
}
});
}).on('error', function(ev){
console.log(ev.message);
});
}, checkInterval);
function padding2(num){
if(num < 10) {
num = '0' + num;
}
return num.toString();
}