forked from matryer/xbar-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathisItUp.5s.js
executable file
·92 lines (77 loc) · 2.8 KB
/
isItUp.5s.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
90
91
92
#!/usr/bin/env /usr/local/bin/node
// <bitbar.title>Is It Up?</bitbar.title>
// <bitbar.version>v1.1</bitbar.version>
// <bitbar.author>Zachary David Saunders</bitbar.author>
// <bitbar.author.github>ZacharyDavidSaunders</bitbar.author.github>
// <bitbar.desc>A MacOs Menu Bar (BitBar) plugin that allows you to check whether or not a website is currently up (online).</bitbar.desc>
// <bitbar.dependencies>node.js</bitbar.dependencies>
// <bitbar.image>https://i.imgur.com/BxHFJMn.png</bitbar.image>
/*jshint esversion: 6 */
//👋👋👋 Feel free to change the following varaibles to best suit your needs.
var upMessage = 'Yes ✅';
var unknownMessage = 'Error, click for details ⚠️';
var downMessage = 'No 🔥';
var website = "www.google.com";
//<--- DO NOT EDIT THE CODE BELOW THIS LINE. --->
const https = require('https');
var version = "v1.1";
renderPlugin();
function renderPlugin(){
checkWebsite(function(status){
var menuBarIcon = "Is \""+website+"\" up?: " + getMessage(status);
if(status === "up"){
console.log(menuBarIcon+" |color:green");
console.log("---");
console.log("Visit \""+website+"\". [Click to visit site] |href=https://"+website);
}else if (status === "down"){
console.log(menuBarIcon+" |color:red");
}else{
console.log(menuBarIcon+" |color:yellow");
console.log("---");
console.log("Error: Unable to contact \""+ website+"\".");
console.log("Please verify that you entered the website correctly (remember, you don't need a www/http/https prefix).");
console.log("If this problem persists, isitdown.site's API may be unavailable.");
}
console.log("---");
console.log("Powered by \"isitdown.site\". [Click to visit site] |href=https://isitdown.site");
console.log("For more information, please see the github repository. [Click to visit site] |href=https://github.com/ZacharyDavidSaunders/IsItUp-BitBarPlugin");
console.log("---");
console.log("Version: "+version+"\n© Zachary David Saunders 2018 |size:10");
});
}
function checkWebsite(callback){
var result;
https.get('https://isitdown.site/api/'+website, (resp) => {
var data = '';
resp.on('data', (chunk) => {
data += chunk;
});
resp.on('end', () => {
try{
var response = JSON.parse(data);
if(response.isitdown == false){
result = "up";
}else if (response.isitdown == true){
result = "down";
}else{
result = "unknown";
}
}catch(error){
result = "unknown";
}
callback(result);
});
}).on("error", (err) => {
result = "unknown";
callback(result);
});
}
function getMessage(status){
if(status === "up"){
return upMessage;
}else if (status === "down"){
return downMessage;
}else{
return unknownMessage;
}
}