A MacOs Menu Bar (BitBar) plugin that allows you to check whether or not a website is currently up (online).
#!/usr/bin/env /usr/local/bin/node
// <xbar.title>Is It Up?</xbar.title>
// <xbar.version>v1.1</xbar.version>
// <xbar.author>Zachary David Saunders</xbar.author>
// <xbar.author.github>ZacharyDavidSaunders</xbar.author.github>
// <xbar.desc>A MacOs Menu Bar (BitBar) plugin that allows you to check whether or not a website is currently up (online).</xbar.desc>
// <xbar.dependencies>node.js</xbar.dependencies>
// <xbar.image>https://i.imgur.com/BxHFJMn.png</xbar.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;
}
}