Skip to content

Instantly share code, notes, and snippets.

@Critter
Forked from spencerwooo/termiWidget.js
Created August 27, 2020 13:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Critter/8ff47f1ba2c8beee4a4fea264bf132af to your computer and use it in GitHub Desktop.
Save Critter/8ff47f1ba2c8beee4a4fea264bf132af 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"
// 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