├── README.md ├── lockscreen-rss-widget_no_rotation.js └── lockscreen-rss-widget_rotation.js /README.md: -------------------------------------------------------------------------------- 1 | # RSS Lockscreen Widget (Scriptable) 2 | This is a simple widget that allows you to add your favorite news site via RSS right on your iOS lockscreen. 3 | 4 | 5 |

Sriptable RSS News Widget

6 | 7 | ## Features 8 | * Display a custom RSS feed right on your lock screen 9 | * A click on the news opens up the article in your browser 10 | * Display the latest article 11 | * to use that, download [lockscreen-rss-widget_no_rotation.js][download_script] 12 | * Display the five latest articles in rotation 13 | * to use that, download [lockscreen-rss-widget_rotation.js][download_script] 14 | * see more under [Rotation feature] 15 | 16 | ## Prepare to use the widget 17 | To use this widget, you need to do the following steps: 18 | * Install Scriptable from the [App Store] 19 | * Download the script [here][download_script] 20 | * Open the script and enter the link to the RSS feed of your favorite news site (see [Edit Script]) 21 | * After you're done with the changes, you can add the widget to your lock screen. These are the settings after selecting the script: 22 | * "When interacting": Run script 23 | * "Parameter": leave it blank 24 | 25 | [App Store]:https://apps.apple.com/de/app/scriptable/id1405459188 26 | [download_script]:https://github.com/leon47331/scriptable-lockscreen-rss-widget/releases 27 | [Edit Script]:https://github.com/leon47331/scriptable-lockscreen-rss-widget/#edit-script 28 | [Rotation Feature]:https://github.com/leon47331/scriptable-lockscreen-rss-widget/#rotation-feature 29 | 30 | 31 | ## Edit script 32 | Now that you have the script in Scriptable, it's time to enter your favorite news site.
33 | These are the changes you need to make in the script: 34 | 35 | ```javascript 36 | const url = "RSS-FEED-URL"; 37 | const srcName = "SITE-NAME"; 38 | ``` 39 | Replace ```RSS-FEED-URL``` with the URL of the RSS feed you'd like to add. 40 | Replace ```SITE-NAME``` with the name of the site that should be displayed on the lock screen. 41 | 42 | ## Rotation feature 43 | Version 1.1.0 supports a rotation feature where the script automatically selects one of the 5 latest articles from the RSS feed. This value can be changed by editing the following value: 44 | ```javascript 45 | const rotationValue = 5; 46 | ``` -------------------------------------------------------------------------------- /lockscreen-rss-widget_no_rotation.js: -------------------------------------------------------------------------------- 1 | // Scriptable Lockscreen RSS widget (without rotation feature) 2 | // Version: v1.1.1 3 | // Author: @leon47331 4 | 5 | const url = "RSS-FEED-URL"; 6 | const srcName = "SITE-NAME" 7 | 8 | async function getRSSFeed() { 9 | let req = new Request(url); 10 | let feed = await req.loadString(); 11 | let items = []; 12 | 13 | let regex = /[\s\S]*?(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?<\/title>[\s\S]*?<link>(.*?)<\/link>[\s\S]*?<\/item>/g; 14 | let match; 15 | 16 | while ((match = regex.exec(feed)) !== null) { 17 | let title = match[1]; 18 | let link = match[2]; 19 | title = title.replace(/"/g, "\""); 20 | title = title.replace(/„/g, "„").replace(/“/g, "“"); 21 | title = title.replace(/–/g, "–"); 22 | 23 | items.push({ title, link }); 24 | } 25 | 26 | return items; 27 | } 28 | 29 | let widget = new ListWidget(); 30 | 31 | async function createWidget() { 32 | let rssItems = await getRSSFeed(); 33 | 34 | if (rssItems.length > 0) { 35 | let latestItem = rssItems[0]; 36 | let title = latestItem.title; 37 | let link = latestItem.link; 38 | 39 | let stack = widget.addStack(); 40 | stack.layoutVertically(); 41 | 42 | 43 | let titleText = widget.addText(srcName); 44 | titleText.font = Font.boldSystemFont(13); 45 | titleText.textColor = new Color("#adacac"); 46 | widget.addSpacer(1); 47 | let newsText = widget.addText(title); 48 | newsText.font = Font.semiboldMonospacedSystemFont(12); 49 | 50 | widget.url = link 51 | 52 | } else { 53 | widget.addText("No new articles available"); 54 | widget.url = "scriptable://" // FIXME: Placeholder 55 | } 56 | 57 | Script.setWidget(widget); 58 | Script.complete(); 59 | } 60 | 61 | await createWidget(); 62 | -------------------------------------------------------------------------------- /lockscreen-rss-widget_rotation.js: -------------------------------------------------------------------------------- 1 | // Scriptable Lockscreen RSS widget (with rotation feature) 2 | // Version: v1.1.1 3 | // Author: @leon47331 4 | 5 | const url = "RSS-FEED-URL"; 6 | const srcName = "SITE-NAME"; 7 | const rotationValue = 5; 8 | 9 | async function getRSSFeed() { 10 | let req = new Request(url); 11 | let feed = await req.loadString(); 12 | let items = []; 13 | 14 | let regex = /<item>[\s\S]*?<title>(?:<!\[CDATA\[)?(.*?)(?:\]\]>)?<\/title>[\s\S]*?<link>(.*?)<\/link>[\s\S]*?<\/item>/g; 15 | let match; 16 | 17 | while ((match = regex.exec(feed)) !== null) { 18 | let title = match[1]; 19 | let link = match[2]; 20 | title = title.replace(/"/g, "\""); 21 | title = title.replace(/„/g, "„").replace(/“/g, "“"); 22 | title = title.replace(/–/g, "–"); 23 | 24 | items.push({ title, link }); 25 | } 26 | 27 | return items.slice(0, rotationValue); 28 | } 29 | 30 | async function getRandomEntry(items) { 31 | if (items.length === 0) return null; 32 | 33 | let randomIndex = Math.floor(Math.random() * items.length); 34 | return items[randomIndex]; 35 | } 36 | 37 | let widget = new ListWidget(); 38 | 39 | async function createWidget() { 40 | let rssItems = await getRSSFeed(); 41 | let latestItem = await getRandomEntry(rssItems); 42 | 43 | if (latestItem !== null) { 44 | let title = latestItem.title; 45 | let link = latestItem.link; 46 | 47 | let stack = widget.addStack(); 48 | stack.layoutVertically(); 49 | 50 | let titleText = widget.addText(srcName); 51 | titleText.font = Font.boldSystemFont(13); 52 | titleText.textColor = new Color("#adacac"); 53 | widget.addSpacer(1); 54 | let newsText = widget.addText(title); 55 | newsText.font = Font.semiboldMonospacedSystemFont(12); 56 | 57 | widget.url = link; 58 | } else { 59 | widget.addText("No new articles available"); 60 | widget.url = "scriptable://" // FIXME: Placeholder 61 | } 62 | 63 | Script.setWidget(widget); 64 | Script.complete(); 65 | } 66 | 67 | await createWidget(); 68 | --------------------------------------------------------------------------------