Last active
May 19, 2022 08:24
-
-
Save ignacioribes/44d11fa16be26a2214429dd0605e9d6e to your computer and use it in GitHub Desktop.
A scriptable Gas Price Widget
This file contains 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
const ethGasStationApiUrl = `https://ethgasstation.info/api/ethgasAPI.json`; | |
const req = new Request(ethGasStationApiUrl); | |
const res = await req.loadJSON(); | |
if (config.runsInWidget) { | |
const widget = new ListWidget(); | |
const title = widget.addText("Gas Prices"); | |
title.textColor = Color.white(); | |
title.textOpacity = 0.8; | |
title.font = new Font("Helvetica-Light ", 10); | |
widget.addSpacer(2); | |
const fastestGas = (res.fastest/10); | |
const fastest = widget.addText(`Trader: ${fastestGas}`); | |
fastest.textColor = Color.white(); | |
fastest.font = new Font("Courier", 14); | |
widget.addSpacer(2); | |
const fastGas = (res.fast/10); | |
const fast = widget.addText(`Fast: ${fastGas}`); | |
fast.textColor = Color.white(); | |
fast.font = new Font("Courier", 14); | |
widget.addSpacer(2); | |
const averageGas = (res.average/10); | |
const average = widget.addText(`Standard: ${averageGas}`); | |
average.textColor = Color.white(); | |
average.font = new Font("Courier", 14); | |
widget.addSpacer(2); | |
const date = new Date(); | |
const lastUpdate = widget.addText(`LastUpdate: ${date.getHours()}:${date.getMinutes()}`); | |
lastUpdate.textColor = Color.white(); | |
title.textOpacity = 0.8; | |
lastUpdate.font = new Font("Helvetica-Light", 10); | |
if (fastGas < 100) { | |
let n = new Notification() | |
n.title = "🤑 Gas cheap! Under 100" | |
// n.subtitle = "" | |
n.body = "Make yours swap baby" | |
n.sound = "alert" | |
n.schedule(); | |
} | |
Script.setWidget(widget); | |
Script.complete(); | |
} |
Do i have to add something in the html? Cause it doesnt work for me.
This is a widget for https://scriptable.app/ is not for a webpage.
Doesn’t work for me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do i have to add something in the html? Cause it doesnt work for me.