// Variables used by Scriptable. // These must be at the very top of the file. Do not edit. // icon-color: cyan; icon-glyph: calendar-alt; /** * Виджет расписания УКГП для Scriptable (iOS) * Группа: ГЭМ-23ДО * Тема: dark * Сервер: https://ukgp.unfit.website */ const GROUP = "ГЭМ-23ДО"; const THEME = "dark"; const API_URL = "https://ukgp.unfit.website/api/schedule?group=" + encodeURIComponent(GROUP) + "&day=auto&lang=ru"; async function createWidget() { const widget = new ListWidget(); widget.backgroundColor = new Color("#0f172a"); let data = null; try { const req = new Request(API_URL); req.timeoutInterval = 10; data = await req.loadJSON(); } catch (e) { console.error(e); } if (!data || !data.pairs || data.pairs.length === 0) { const title = widget.addText("ГАПОУ УКГП"); title.textColor = new Color("#94a3b8"); title.font = Font.boldSystemFont(12); widget.addSpacer(8); const msg = widget.addText(data ? (data.is_tomorrow ? "Завтра пар нет 🎉" : "Сегодня пар нет 🎉") : "Не удалось загрузить"); msg.textColor = Color.white(); msg.font = Font.boldSystemFont(15); return widget; } widget.url = "https://ukgp.unfit.website/widget?group=" + encodeURIComponent(data.group) + "&theme=dark&lang=ru"; // Header row const headerStack = widget.addStack(); headerStack.layoutHorizontally(); const titleText = headerStack.addText("УКГП • " + data.group); titleText.textColor = new Color("#38bdf8"); titleText.font = Font.boldSystemFont(13); headerStack.addSpacer(); const tagText = headerStack.addText(data.is_tomorrow ? "Завтра" : "Сегодня"); tagText.textColor = data.is_tomorrow ? new Color("#fbbf24") : new Color("#4ade80"); tagText.font = Font.boldSystemFont(11); widget.addSpacer(4); const dayText = widget.addText(data.day); dayText.textColor = Color.white(); dayText.font = Font.boldSystemFont(14); widget.addSpacer(8); const maxPairs = config.widgetFamily === "large" ? 6 : 4; const pairsToShow = data.pairs.slice(0, maxPairs); for (const p of pairsToShow) { const row = widget.addStack(); row.layoutHorizontally(); row.centerAlignContent(); // Pair badge const badgeStack = row.addStack(); badgeStack.backgroundColor = new Color("#1e293b"); badgeStack.cornerRadius = 4; badgeStack.setPadding(2, 6, 2, 6); const num = badgeStack.addText(p.pair + "п"); num.textColor = new Color("#38bdf8"); num.font = Font.boldSystemFont(11); row.addSpacer(8); // Subject & Room const subText = row.addText(p.subject + (p.room ? " (" + p.room + ")" : "")); subText.textColor = Color.white(); subText.font = Font.mediumSystemFont(12); subText.lineLimit = 1; widget.addSpacer(4); } if (data.pairs.length > maxPairs) { widget.addSpacer(2); const moreText = widget.addText("Еще " + (data.pairs.length - maxPairs) + " пар (нажмите, чтобы открыть) ➔"); moreText.textColor = new Color("#94a3b8"); moreText.font = Font.systemFont(10); } // Auto refresh interval: 15 minutes const nextRefresh = new Date(Date.now() + 15 * 60 * 1000); widget.refreshAfterDate = nextRefresh; return widget; } const widget = await createWidget(); if (config.runsInWidget) { Script.setWidget(widget); } else { widget.presentMedium(); } Script.complete();