pyblock/PyBLØCK Widget.scriptable
2023-04-08 08:15:20 -03:00

126 lines
3.3 KiB
Text

// Made by PyBLØCK Crew
let req = new Request("https://mempool.space/api/blocks/tip/height");
let blockHeight = await req.loadString();
let count = new Request('https://bitcoinexplorer.org/api/mempool/summary');
let tx = await count.loadJSON();
number = tx.size.toString();
let make = new Request('https://mempool.space/api/v1/fees/recommended');
let json = await make.loadJSON();
fast = json.fastestFee.toString();
halfHour = json.halfHourFee.toString();
hour = json.hourFee.toString();
let call = new Request('https://bitcoinexplorer.org/api/blockchain/coins');
let supply = await call.loadJSON();
coins = supply.supply.toString();
let get = new Request('https://bitcoinexplorer.org/api/price/sats');
let MoscowTime = await get.loadJSON();
psats = MoscowTime.usd.toString();
let prin = new Request('https://bitcoinexplorer.org/api/price');
let Price = await prin.loadJSON();
pusd = Price.usd.toString();
let widget = await createWidget();
// Check where the script is running
if (config.runsInWidget)
{
// Runs inside a widget so add it to the homescreen widget
Script.setWidget(widget);
}
else
{
// Show the medium widget inside the app
widget.presentLarge();
}
Script.complete();
async function createWidget()
{
// Create new empty ListWidget instance
let listwidget = new ListWidget();
// Set new background color
listwidget.backgroundColor = new Color("#000000");
// add 10 second to now
let nextRefresh = Date.now() + 1000*10
listwidget.refreshAfterDate = new Date(nextRefresh)
// Add widget heading
let sns = new Request('https://raw.githubusercontent.com/curly60e/pyblock/master/pybitblock/resources/images/Logo.PNG');
let pyp = await sns.loadImage();
let tt = listwidget.addImage(pyp).centerAlignImage()
let heading = listwidget.addText(blockHeight);
heading.centerAlignText();
heading.font = Font.boldSystemFont(70);
heading.textColor = new Color("#0aff17");
let txs = listwidget.addText("▁▂▃▄▅▆▇ " + number + " ▇▆▅▄▃▂▁");
txs.centerAlignText();
txs.font = Font.boldSystemFont(13);
txs.textColor = new Color("#FFFFFF");
let wdgDesc = listwidget.addText("🟥 🟨 🟩");
// Add widget heading
let mem = listwidget.addText(fast + " " + halfHour + " " + hour);
wdgDesc.centerAlignText();
mem.centerAlignText();
wdgDesc.font = Font.boldSystemFont(10);
if(fast < 10)
mem.font = Font.boldSystemFont(30);
else if(fast < 100)
mem.font = Font.boldSystemFont(30);
else
mem.font = Font.boldSystemFont(30);
wdgDesc.textColor = new Color("#EEEEEE");
mem.textColor = new Color("#0aff17");
let pr = listwidget.addText(pusd + " $ = 1 ₿itcoin");
pr.centerAlignText();
pr.font = Font.boldSystemFont(13);
pr.textColor = new Color("#EEEEEE")
let ms = listwidget.addText(psats + " 丰 = 1 $");
ms.centerAlignText();
ms.font = Font.boldSystemFont(22);
ms.textColor = new Color("#0aff17")
let coin = listwidget.addText(coins + " Supply");
coin.centerAlignText();
coin.font = Font.boldSystemFont(13);
coin.textColor = new Color("#EEEEEE")
let req = new Request('https://pbs.twimg.com/media/E3IikexWYAQfqY2.png');
let SN = await req.loadImage();
// Add widget heading
let gn = listwidget.addImage(SN).centerAlignImage()
// Return the created widget
return listwidget;
}