/
app.js
68 lines (58 loc) · 1.2 KB
/
app.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
var check = 30; //Check every X seconds
var url = "http://example.com";
var msg = "Yay! " + url + " has been updated!";
//Don't Edit!
global.md5 = function(str) {
var crypto = require('crypto');
return crypto.createHash('md5').update(str).digest('hex');
};
global.escapeshell = function(cmd) { //http://stackoverflow.com/a/7685469
return '"'+cmd.replace(/(["\s'$`\\])/g,'\\$1')+'"';
};
global.say = function(string)
{
var os = require('os');
if (os.type() === 'Darwin')
{
var exec = require('child_process').exec;
exec("say " + escapeshell(string), function(error, stdout, stderr)
{
console.log(stderr);
});
}
};
var hashedContent = null;
var HTTPRequest = require('HTTPRequest');
function ping()
{
console.log("Checking...");
HTTPRequest.get(url, function(status, headers, content)
{
if (status == 200 || status == 302)
{
if (hashedContent == null)
{
hashedContent = md5(content);
}
else
{
var tempHash = md5(content);
if (hashedContent != tempHash)
{
console.log(msg);
say(msg);
}
hashedContent = tempHash;
}
}
else
{
console.log("Http Error: " + status);
}
});
}
ping();
setInterval(function()
{
ping();
}, check * 1000);