Skip to content

Instantly share code, notes, and snippets.

@dkordik
Last active March 19, 2023 00:16
Show Gist options
  • Save dkordik/d4c9b253274cf3e5589df5be4874b6d3 to your computer and use it in GitHub Desktop.
Save dkordik/d4c9b253274cf3e5589df5be4874b6d3 to your computer and use it in GitHub Desktop.
xbar/BitBar plugin to show currently connected ISP logo. Just added T-Mobile and Verizon, for starters. But you can see how you could easily add others.
#!/usr/bin/env /usr/local/bin/node
// <xbar.title>Current ISP name</xbar.title>
// <xbar.version>v2.1.7-beta</xbar.version>
// <xbar.author>Dan Kordik</xbar.author>
// <xbar.author.github>dkordik</xbar.author.github>
// <xbar.desc>Displays current ISP name</xbar.desc>
// <xbar.dependencies></xbar.dependencies>
const http = require("http");
const url = "http://ip-api.com/json";
// find a good logo image online
// resize to 144dpi, 40x40 pixels - I used the built-in Preview app on macOS
// convert to base64 - I used https://codebeautify.org/image-to-base64-converter
const ISP_LOGOS = {
TMOBILE:
"iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAAAXNSR0IArs4c6QAAAIRlWElmTU0AKgAAAAgABQESAAMAAAABAAEAAAEaAAUAAAABAAAASgEbAAUAAAABAAAAUgEoAAMAAAABAAIAAIdpAAQAAAABAAAAWgAAAAAAAACQAAAAAQAAAJAAAAABAAOgAQADAAAAAQABAACgAgAEAAAAAQAAACigAwAEAAAAAQAAACgAAAAAaN6HOQAAAAlwSFlzAAAWJQAAFiUBSVIk8AAAAVlpVFh0WE1MOmNvbS5hZG9iZS54bXAAAAAAADx4OnhtcG1ldGEgeG1sbnM6eD0iYWRvYmU6bnM6bWV0YS8iIHg6eG1wdGs9IlhNUCBDb3JlIDYuMC4wIj4KICAgPHJkZjpSREYgeG1sbnM6cmRmPSJodHRwOi8vd3d3LnczLm9yZy8xOTk5LzAyLzIyLXJkZi1zeW50YXgtbnMjIj4KICAgICAgPHJkZjpEZXNjcmlwdGlvbiByZGY6YWJvdXQ9IiIKICAgICAgICAgICAgeG1sbnM6dGlmZj0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wHpXwZ7r6sNsW+C2q7+XvadPx1pDv31vOf/V8DLo/juat0hfoUe+ZvZjee2nlshVHBKiG0EYiyRx72gMypUGSAXG4eC3KMdQ9BiqvYV77TJATUD0Cq7AF90Si0pAbhCasVMY5PvyERQd3T4V6PCKe0Are3UGtLUJ3fyActLR1Vhc19sdL1TmPrgbhQ9n7QTVXRHGY6JaR+E/vTriuQnAWFtIMWdB5X46beUxKzoGl1ktq9vfoOCDxtw+JlXvYG5STnfdz7/ZhwSBpakJ9gAAAABJRU5ErkJggg==",
};
const renderIsp = (ispString) => {
if (ispString.includes("T-Mobile")) return `| image=${ISP_LOGOS.TMOBILE}`;
if (ispString.includes("Verizon")) return `| image=${ISP_LOGOS.VERIZON}`;
return ispString;
};
http
.get(url, (res) => {
let data = "";
res.on("data", (chunk) => {
data += chunk;
});
res.on("end", () => {
try {
const cc = JSON.parse(data);
console.log(renderIsp(cc.isp));
console.log("---");
console.log(cc.isp);
// console.log(data.toString());
} catch (err) {
console.log("🚩");
console.log("---");
console.log(err.toString());
}
});
})
.on("error", (err) => {
console.log("🚩");
console.log("---");
console.log(err.toString());
});
@dkordik
Copy link
Author

dkordik commented Mar 19, 2023

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment