Skip to content

Instantly share code, notes, and snippets.

@definiteIymaybe
Forked from spencerwooo/termiWidget.js
Created January 7, 2024 00:29
Show Gist options
  • Save definiteIymaybe/757c8486ddafd94eda94015609ae5d5e to your computer and use it in GitHub Desktop.
Save definiteIymaybe/757c8486ddafd94eda94015609ae5d5e to your computer and use it in GitHub Desktop.
πŸ‹ TermiWidget - Terminal-like Widget for iOS 14, made with Scriptable.
// 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"
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("#29323c"), new Color("#1c1c1c")]
bgColor.locations = [0.0, 1.0]
w.backgroundGradient = bgColor
w.setPadding(12, 15, 15, 12)
w.spacing = 6
const time = new Date()
const dfTime = new DateFormatter()
dfTime.locale = "en"
dfTime.useMediumDateStyle()
dfTime.useNoTimeStyle()
const firstLine = w.addText(`[] ${user} ~$ now`)
firstLine.textColor = Color.white()
firstLine.textOpacity = 0.7
firstLine.font = new Font("Menlo", 11)
const timeLine = w.addText(`[πŸ—“] ${dfTime.string(time)}`)
timeLine.textColor = Color.white()
timeLine.font = new Font("Menlo", 11)
const batteryLine = w.addText(`[πŸ”‹] ${renderBattery()}`)
batteryLine.textColor = new Color("#6ef2ae")
batteryLine.font = new Font("Menlo", 11)
const jikeLine = w.addText(`[πŸ‹] Jike: ${data.jikeFollower}`)
jikeLine.textColor = new Color("#ffcc66")
jikeLine.font = new Font("Menlo", 11)
const telegramLine = w.addText(`[️️] Telegram: ${data.telegram}`)
telegramLine.textColor = new Color("#7dbbae")
telegramLine.font = new Font("Menlo", 11)
const githubLine = w.addText(`[πŸ“Ÿ] GitHub: ${data.github}`)
githubLine.textColor = new Color("#ff9468")
githubLine.font = new Font("Menlo", 11)
const sspaiLine = w.addText(`[] SSPAI: ${data.sspai}`)
sspaiLine.textColor = new Color("#ffa7d3")
sspaiLine.font = new Font("Menlo", 11)
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 res = await request.loadJSON()
return res.data.subsInEachSource
}
function renderBattery() {
const batteryLevel = Device.batteryLevel()
const juice = "#".repeat(Math.floor(batteryLevel * 8))
const used = ".".repeat(8 - 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