Is It Up?

A MacOs Menu Bar (BitBar) plugin that allows you to check whether or not a website is currently up (online).

Image preview of Is It Up? plugin.

isItUp.5s.js

Edit
Open on GitHub
#!/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;
  }
}