Last active
February 18, 2026 06:05
-
-
Save daydream05/82f23f93a93216a812f053d9ce341c56 to your computer and use it in GitHub Desktop.
SimRacing Daily - Scriptable Widget
This file contains hidden or 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
| // SimRacing Daily Widget for Scriptable | |
| const WIDGET_URL = "https://agenthub-widget.clawdbro.workers.dev/widget/simracing"; | |
| async function fetchData() { | |
| try { | |
| const req = new Request(WIDGET_URL); | |
| req.timeoutInterval = 10; | |
| return await req.loadJSON(); | |
| } catch (e) { return null; } | |
| } | |
| function truncate(str, n) { | |
| if (!str) return ""; | |
| return str.length > n ? str.slice(0, n - 1) + "…" : str; | |
| } | |
| async function buildWidget() { | |
| const data = await fetchData(); | |
| const w = new ListWidget(); | |
| const gradient = new LinearGradient(); | |
| gradient.colors = [new Color("#0d0d0d"), new Color("#1a1a2e")]; | |
| gradient.locations = [0, 1]; | |
| w.backgroundGradient = gradient; | |
| w.setPadding(12, 12, 12, 12); | |
| if (!data) { | |
| const err = w.addText("⚠️ Could not load"); | |
| err.textColor = Color.gray(); | |
| err.font = Font.systemFont(11); | |
| return w; | |
| } | |
| const family = config.widgetFamily || "medium"; | |
| const isSmall = family === "small"; | |
| const isLarge = family === "large"; | |
| // Header | |
| const header = w.addStack(); | |
| header.layoutHorizontally(); | |
| const icon = header.addText("🏎️"); | |
| icon.font = Font.systemFont(12); | |
| header.addSpacer(4); | |
| const title = header.addText("SimRacing Daily"); | |
| title.font = Font.boldSystemFont(12); | |
| title.textColor = new Color("#e94560"); | |
| header.addSpacer(); | |
| if (data.publishDate) { | |
| const date = header.addText(data.publishDate); | |
| date.font = Font.systemFont(9); | |
| date.textColor = new Color("#555555"); | |
| } | |
| w.addSpacer(5); | |
| // Headline — always shown | |
| const hl = w.addText(truncate(data.headline, isSmall ? 50 : 75)); | |
| hl.font = Font.semiboldSystemFont(isSmall ? 10 : 11); | |
| hl.textColor = Color.white(); | |
| hl.lineLimit = 2; | |
| w.addSpacer(4); | |
| // TL;DR | |
| const tldrLen = isSmall ? 80 : isLarge ? 300 : 200; | |
| const tl = w.addText(truncate(data.tldr, tldrLen)); | |
| tl.font = Font.systemFont(isSmall ? 9 : 10); | |
| tl.textColor = new Color("#aaaaaa"); | |
| tl.lineLimit = isSmall ? 2 : isLarge ? 6 : 5; | |
| // Alert | |
| if (!isSmall && data.alerts) { | |
| w.addSpacer(5); | |
| const alert = w.addText("⚡ " + truncate(data.alerts, isLarge ? 200 : 120)); | |
| alert.font = Font.systemFont(9); | |
| alert.textColor = new Color("#f0a500"); | |
| alert.lineLimit = isLarge ? 3 : 2; | |
| } | |
| // Quick hits — large only | |
| if (isLarge && data.quickHits) { | |
| w.addSpacer(5); | |
| const qhLabel = w.addText("QUICK HITS"); | |
| qhLabel.font = Font.boldSystemFont(8); | |
| qhLabel.textColor = new Color("#444444"); | |
| w.addSpacer(2); | |
| const qh = w.addText(truncate(data.quickHits, 200)); | |
| qh.font = Font.systemFont(9); | |
| qh.textColor = new Color("#888888"); | |
| qh.lineLimit = 4; | |
| } | |
| w.addSpacer(); | |
| // Footer | |
| const footer = w.addText("r/simracing · " + (data.subscriberCount || 0).toLocaleString()); | |
| footer.font = Font.systemFont(8); | |
| footer.textColor = new Color("#333333"); | |
| return w; | |
| } | |
| const widget = await buildWidget(); | |
| if (config.runsInWidget) { | |
| Script.setWidget(widget); | |
| } else { | |
| await widget.presentMedium(); | |
| } | |
| Script.complete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment