Created
September 3, 2020 04:56
-
-
Save simonbs/5d4fce1edd71d2e2f887c623a58d3dce to your computer and use it in GitHub Desktop.
Scriptable script to check if Slack is down. Works with Siri and widgets.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: orange; icon-glyph: exclamation-triangle; | |
// Checks if Slack is down by examining their status page. Works perfectly with Siri. | |
let url = "https://status.slack.com" | |
let r = new Request(url) | |
if (config.runsWithSiri) { | |
let isDown = await getIsDown(url) | |
if (isDown) { | |
Speech.speak("Yes") | |
} else { | |
Speech.speak("No") | |
} | |
Script.complete() | |
} else if (config.runsInWidget) { | |
let isDown = await getIsDown(url) | |
let widget = createWidget(isDown) | |
Script.setWidget(widget) | |
Script.complete() | |
} else { | |
Safari.openInApp(url) | |
} | |
async function getIsDown(url) { | |
let body = await r.loadString() | |
let needles = [ | |
"up and running", | |
"smooth sailing" | |
] | |
let foundNeedles = needles.filter(n => { | |
return body.includes(n) | |
}) | |
return foundNeedles.length <= 0 | |
} | |
function createWidget(isDown) { | |
let w = new ListWidget() | |
let emoji | |
if (isDown) { | |
emoji = "⚠️" | |
} else { | |
emoji = "✅" | |
} | |
let wtext = w.addText(emoji) | |
wtext.centerAlignText() | |
wtext.textSize = 48 | |
return w | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment