add single text scroll option #57

This commit is contained in:
Matt Walsh
2025-06-28 09:20:10 -05:00
parent fda44e95fc
commit 9f9667c895
2 changed files with 33 additions and 6 deletions

View File

@@ -11,7 +11,7 @@ const changeEnable = (newValue) => {
let newDisplay; let newDisplay;
if (newValue) { if (newValue) {
// add the feed to the scroll // add the feed to the scroll
getFeed(customFeed.value); parseFeed(customFeed.value);
// show the string box // show the string box
newDisplay = 'block'; newDisplay = 'block';
} else { } else {
@@ -26,14 +26,37 @@ const changeEnable = (newValue) => {
} }
}; };
// get the rss feed and then swap out the current weather scroll // parse the feed/text provided
const getFeed = async (url) => { const parseFeed = (textInput) => {
// skip getting the feed on first run // skip getting the feed on first run
if (firstRun) return; if (firstRun) return;
// test validity // 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 // get the text as a string
// it needs to be proxied, use a free service // it needs to be proxied, use a free service
const rssResponse = await json(`https://api.allorigins.win/get?url=${url}`); const rssResponse = await json(`https://api.allorigins.win/get?url=${url}`);
@@ -76,7 +99,7 @@ const changeFeed = (newValue) => {
if (firstRun) return; if (firstRun) return;
if (customFeedEnable.value) { if (customFeedEnable.value) {
getFeed(newValue); parseFeed(newValue);
} }
}; };
@@ -85,10 +108,11 @@ const customFeed = new Setting('customFeed', {
defaultValue: '', defaultValue: '',
type: 'string', type: 'string',
changeAction: changeFeed, changeAction: changeFeed,
placeholder: 'Text or URL',
}); });
const customFeedEnable = new Setting('customFeedEnable', { const customFeedEnable = new Setting('customFeedEnable', {
name: 'Enable Custom RSS Feed', name: 'Enable RSS Feed/Text',
defaultValue: false, defaultValue: false,
changeAction: changeEnable, changeAction: changeEnable,
}); });

View File

@@ -11,6 +11,7 @@ const DEFAULTS = {
sticky: true, sticky: true,
values: [], values: [],
visible: true, visible: true,
placeholder: '',
}; };
class Setting { class Setting {
@@ -31,6 +32,7 @@ class Setting {
this.values = options.values; this.values = options.values;
this.visible = options.visible; this.visible = options.visible;
this.changeAction = options.changeAction; this.changeAction = options.changeAction;
this.placeholder = options.placeholder;
// get value from url // get value from url
const urlValue = parseQueryString()?.[`settings-${shortName}-${this.type}`]; const urlValue = parseQueryString()?.[`settings-${shortName}-${this.type}`];
@@ -141,6 +143,7 @@ class Setting {
textInput.value = this.myValue; textInput.value = this.myValue;
textInput.id = `settings-${this.shortName}-string`; textInput.id = `settings-${this.shortName}-string`;
textInput.name = `settings-${this.shortName}-string`; textInput.name = `settings-${this.shortName}-string`;
textInput.placeholder = this.placeholder;
// set button // set button
const setButton = document.createElement('input'); const setButton = document.createElement('input');
setButton.type = 'button'; setButton.type = 'button';