-
-
Save Critter/8ff47f1ba2c8beee4a4fea264bf132af to your computer and use it in GitHub Desktop.
π TermiWidget - Terminal-like Widget for iOS 14, made with Scriptable.
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
// Variables used by Scriptable. | |
// These must be at the very top of the file. Do not edit. | |
// icon-color: orange; icon-glyph: quote-right; | |
// Change these to your usernames! | |
const user = "spencer" | |
const jike = "4DDA0425-FB41-4188-89E4-952CA15E3C5E" | |
const telegram = "realSpencerWoo" | |
const github = "spencerwooo" | |
const sspai = "spencerwoo" | |
// Follower and subscriber stats are provided by my own API, which you can also use: | |
// URL: https://github.com/spencerwooo/Substats | |
const data = await fetchData() | |
const widget = createWidget(data) | |
Script.setWidget(widget) | |
Script.complete() | |
function createWidget(data) { | |
console.log(data) | |
const w = new ListWidget() | |
const bgColor = new LinearGradient() | |
bgColor.colors = [new Color("#1c1c1c"), new Color("#29323c")] | |
bgColor.locations = [0.0, 1.0] | |
w.backgroundGradient = bgColor | |
w.centerAlignContent() | |
const time = new Date() | |
const dfTime = new DateFormatter() | |
dfTime.locale = "en" | |
dfTime.useMediumDateStyle() | |
dfTime.useNoTimeStyle() | |
const firstLine = w.addText(`[π±] ${user}:~ $ now`) | |
firstLine.textSize = 12 | |
firstLine.textColor = Color.white() | |
firstLine.textOpacity = 0.7 | |
const timeLine = w.addText(`[π] ${dfTime.string(time)}`) | |
timeLine.textSize = 12 | |
timeLine.textColor = Color.white() | |
const batteryLine = w.addText(`[π] ${renderBattery()}`) | |
batteryLine.textSize = 12 | |
batteryLine.textColor = new Color("#6ef2ae") | |
const jikeLine = w.addText(`[π] Jike: ${data.jikeFollower}`) | |
jikeLine.textSize = 12 | |
jikeLine.textColor = new Color("#ffcc66") | |
const telegramLine = w.addText(`[οΈβοΈ] Telegram: ${data.telegram}`) | |
telegramLine.textSize = 12 | |
telegramLine.textColor = new Color("#7dbbae") | |
const githubLine = w.addText(`[π] GitHub: ${data.github}`) | |
githubLine.textSize = 12 | |
githubLine.textColor = new Color("#ff9468") | |
const sspaiLine = w.addText(`[π] SSPAI: ${data.sspai}`) | |
sspaiLine.textSize = 12 | |
sspaiLine.textColor = new Color("#ffa7d3") | |
return w | |
} | |
async function fetchData() { | |
const url = `https://api.spencerwoo.com/substats/?source=jikeFollower&queryKey=${jike}` | |
+ `&source=telegram&queryKey=${telegram}` | |
+ `&source=github&queryKey=${github}` | |
+ `&source=sspai&queryKey=${sspai}` | |
const request = new Request(url) | |
const resp = await request.loadJSON() | |
const data = resp.data.subsInEachSource | |
return data | |
} | |
function renderBattery() { | |
const batteryLevel = Device.batteryLevel() | |
const juice = "#".repeat(Math.floor(batteryLevel * 9)) | |
const used = ".".repeat(9 - juice.length) | |
const batteryAscii = `[${juice}${used}] ${Math.round(batteryLevel * 100)}%` | |
return batteryAscii | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment