From 9f9667c895bfef4f83b2ba1e6ce83c7e9c74b558 Mon Sep 17 00:00:00 2001 From: Matt Walsh Date: Sat, 28 Jun 2025 09:20:10 -0500 Subject: [PATCH] add single text scroll option #57 --- server/scripts/modules/custom-rss-feed.mjs | 36 ++++++++++++++++++---- server/scripts/modules/utils/setting.mjs | 3 ++ 2 files changed, 33 insertions(+), 6 deletions(-) diff --git a/server/scripts/modules/custom-rss-feed.mjs b/server/scripts/modules/custom-rss-feed.mjs index 33e566b..059f8e6 100644 --- a/server/scripts/modules/custom-rss-feed.mjs +++ b/server/scripts/modules/custom-rss-feed.mjs @@ -11,7 +11,7 @@ const changeEnable = (newValue) => { let newDisplay; if (newValue) { // add the feed to the scroll - getFeed(customFeed.value); + parseFeed(customFeed.value); // show the string box newDisplay = 'block'; } else { @@ -26,14 +26,37 @@ const changeEnable = (newValue) => { } }; -// get the rss feed and then swap out the current weather scroll -const getFeed = async (url) => { +// parse the feed/text provided +const parseFeed = (textInput) => { // skip getting the feed on first run if (firstRun) return; // test validity - if (url === undefined || url === '') return; + if (textInput === undefined || textInput === '') { + resetScroll(); + } + // test for url + if (textInput.match(/https?:\/\//)) { + getFeed(textInput); + return; + } + + // add single text scroll + resetScroll(); + addScroll( + () => ( + { + type: 'scroll', + text: textInput, + }), + // keep the existing scroll + true, + ); +}; + +// get the rss feed and then swap out the current weather scroll +const getFeed = async (url) => { // get the text as a string // it needs to be proxied, use a free service const rssResponse = await json(`https://api.allorigins.win/get?url=${url}`); @@ -76,7 +99,7 @@ const changeFeed = (newValue) => { if (firstRun) return; if (customFeedEnable.value) { - getFeed(newValue); + parseFeed(newValue); } }; @@ -85,10 +108,11 @@ const customFeed = new Setting('customFeed', { defaultValue: '', type: 'string', changeAction: changeFeed, + placeholder: 'Text or URL', }); const customFeedEnable = new Setting('customFeedEnable', { - name: 'Enable Custom RSS Feed', + name: 'Enable RSS Feed/Text', defaultValue: false, changeAction: changeEnable, }); diff --git a/server/scripts/modules/utils/setting.mjs b/server/scripts/modules/utils/setting.mjs index 7c70a56..a4075fc 100644 --- a/server/scripts/modules/utils/setting.mjs +++ b/server/scripts/modules/utils/setting.mjs @@ -11,6 +11,7 @@ const DEFAULTS = { sticky: true, values: [], visible: true, + placeholder: '', }; class Setting { @@ -31,6 +32,7 @@ class Setting { this.values = options.values; this.visible = options.visible; this.changeAction = options.changeAction; + this.placeholder = options.placeholder; // get value from url const urlValue = parseQueryString()?.[`settings-${shortName}-${this.type}`]; @@ -141,6 +143,7 @@ class Setting { textInput.value = this.myValue; textInput.id = `settings-${this.shortName}-string`; textInput.name = `settings-${this.shortName}-string`; + textInput.placeholder = this.placeholder; // set button const setButton = document.createElement('input'); setButton.type = 'button';