Skip to content

Instantly share code, notes, and snippets.

@ignacioribes
Last active May 19, 2022 08:24
Show Gist options
  • Star 13 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ignacioribes/44d11fa16be26a2214429dd0605e9d6e to your computer and use it in GitHub Desktop.
Save ignacioribes/44d11fa16be26a2214429dd0605e9d6e to your computer and use it in GitHub Desktop.
A scriptable Gas Price Widget
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();
}
@brenolasserre
Copy link

Do i have to add something in the html? Cause it doesnt work for me.

@ignacioribes
Copy link
Author

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.

@Hodgy007
Copy link

Doesn’t work for me

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