Created
June 3, 2025 15:35
-
-
Save sy5121/6da6c758abfa1e91896293cd2e86304b to your computer and use it in GitHub Desktop.
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
| // Variables used by Scriptable. | |
| // These must be at the very top of the file. Do not edit. | |
| // icon-color: teal; icon-glyph: magic; | |
| // CONFIG | |
| const URL = "https://www.caranddriver.com/features/g15383106/future-cars/"; | |
| let req = new Request(URL); | |
| let html = await req.loadString(); | |
| // Roughly split content by <h2> blocks | |
| let blocks = html.split("<h2"); | |
| let cars = []; | |
| // Parse first 3 car entries | |
| for (let block of blocks.slice(1, 4)) { | |
| let titleMatch = block.match(/>([^<]{5,60})<\/h2>/); | |
| let imgMatch = block.match(/<img[^>]+src="([^"]+)"/); | |
| let dateMatch = block.match(/(?:Coming|Releases in)\s+([A-Za-z]+\s+\d{4})/i); | |
| if (titleMatch) { | |
| cars.push({ | |
| title: titleMatch[1].trim(), | |
| image: imgMatch ? imgMatch[1] : null, | |
| date: dateMatch ? dateMatch[1].trim() : "Date not listed" | |
| }); | |
| } | |
| } | |
| // Fallback if nothing found | |
| if (cars.length === 0) cars.push({ title: "No upcoming cars found", image: null, date: "" }); | |
| // Create widget | |
| let widget = new ListWidget(); | |
| widget.backgroundColor = Color.black(); | |
| // Header | |
| let header = widget.addText("π Upcoming Car Releases"); | |
| header.font = Font.heavySystemFont(20); | |
| header.textColor = Color.white(); | |
| widget.addSpacer(8); | |
| // Show each car | |
| for (let car of cars) { | |
| // Image | |
| if (car.image) { | |
| try { | |
| let imgReq = new Request(car.image); | |
| let img = await imgReq.loadImage(); | |
| let imgStack = widget.addStack(); | |
| let imgView = imgStack.addImage(img); | |
| imgView.imageSize = new Size(300, 100); | |
| imgView.cornerRadius = 6; | |
| widget.addSpacer(6); | |
| } catch (e) { | |
| // Skip if image fails | |
| } | |
| } | |
| // Title | |
| let title = widget.addText(car.title); | |
| title.font = Font.boldSystemFont(16); | |
| title.textColor = Color.white(); | |
| // Date | |
| let date = widget.addText("π " + car.date); | |
| date.font = Font.systemFont(12); | |
| date.textColor = Color.lightGray(); | |
| widget.addSpacer(10); | |
| } | |
| // Footer | |
| let timestamp = new Date().toLocaleTimeString(); | |
| let footer = widget.addText("Updated: " + timestamp); | |
| footer.font = Font.systemFont(10); | |
| footer.textColor = Color.gray(); | |
| // Suggest refresh after 30 minutes | |
| widget.refreshAfterDate = new Date(Date.now() + 30 * 60 * 1000); | |
| // Display | |
| if (config.runsInWidget) { | |
| Script.setWidget(widget); | |
| } else { | |
| widget.presentLarge(); // β large preview | |
| } | |
| Script.complete(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment