mirror of
https://github.com/netbymatt/ws4kp.git
synced 2026-04-17 09:09:30 -07:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7bd21bcf1d | ||
|
|
ec65025ae2 | ||
|
|
194e108037 | ||
|
|
d5b7c6630a | ||
|
|
39bafae394 | ||
|
|
ec8fffbb64 | ||
|
|
0a794eae36 | ||
|
|
8c83736aba | ||
|
|
872162080d | ||
|
|
69d2b0f40b |
@@ -336,8 +336,10 @@ When using Docker:
|
|||||||
* **Static deployment**: Mount your `custom.js` file to `/usr/share/nginx/html/scripts/custom.js`
|
* **Static deployment**: Mount your `custom.js` file to `/usr/share/nginx/html/scripts/custom.js`
|
||||||
* **Server deployment**: Mount your `custom.js` file to `/app/server/scripts/custom.js`
|
* **Server deployment**: Mount your `custom.js` file to `/app/server/scripts/custom.js`
|
||||||
|
|
||||||
### RSS feeds and custom scroll
|
### Custom text scroll
|
||||||
If you would like your Weatherstar to have custom scrolling text in the bottom blue bar, or show headlines from an rss feed turn on the setting for `Enable RSS Feed/Text` and then enter a URL or text in the resulting text box. Then press set.
|
If you would like your Weatherstar to have custom scrolling text in the bottom blue bar, turn on the setting for `Enable RSS Feed/Text` and then enter text in the resulting text box. Then press set.
|
||||||
|
|
||||||
|
Tip: You can have Weatherstar select randomly between several text strings on each pass through the current conditions. Use a pipe character to separate string. `Welcome to Weatherstar|Thanks for watching`.
|
||||||
|
|
||||||
## Issue reporting and feature requests
|
## Issue reporting and feature requests
|
||||||
|
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ const mjsSources = [
|
|||||||
'server/scripts/modules/travelforecast.mjs',
|
'server/scripts/modules/travelforecast.mjs',
|
||||||
'server/scripts/modules/progress.mjs',
|
'server/scripts/modules/progress.mjs',
|
||||||
'server/scripts/modules/media.mjs',
|
'server/scripts/modules/media.mjs',
|
||||||
'server/scripts/modules/custom-rss-feed.mjs',
|
'server/scripts/modules/custom-scroll-text.mjs',
|
||||||
'server/scripts/index.mjs',
|
'server/scripts/index.mjs',
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|||||||
@@ -158,6 +158,7 @@ if (process.env?.DIST === '1') {
|
|||||||
// 'npm run build' and then 'DIST=1 npm start'
|
// 'npm run build' and then 'DIST=1 npm start'
|
||||||
app.use('/scripts', express.static('./server/scripts', staticOptions));
|
app.use('/scripts', express.static('./server/scripts', staticOptions));
|
||||||
app.use('/geoip', geoip);
|
app.use('/geoip', geoip);
|
||||||
|
app.use('/music', express.static('./server/music', staticOptions));
|
||||||
|
|
||||||
// render the EJS template in production mode (serve compressed files from dist directory)
|
// render the EJS template in production mode (serve compressed files from dist directory)
|
||||||
app.get('/', (req, res) => { renderIndex(req, res, true); });
|
app.get('/', (req, res) => { renderIndex(req, res, true); });
|
||||||
|
|||||||
4
package-lock.json
generated
4
package-lock.json
generated
@@ -1,12 +1,12 @@
|
|||||||
{
|
{
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "6.4.2",
|
"version": "6.5.2",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "6.4.2",
|
"version": "6.5.2",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"dotenv": "^17.0.1",
|
"dotenv": "^17.0.1",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "ws4kp",
|
"name": "ws4kp",
|
||||||
"version": "6.4.2",
|
"version": "6.5.2",
|
||||||
"description": "Welcome to the WeatherStar 4000+ project page!",
|
"description": "Welcome to the WeatherStar 4000+ project page!",
|
||||||
"main": "index.mjs",
|
"main": "index.mjs",
|
||||||
"type": "module",
|
"type": "module",
|
||||||
|
|||||||
@@ -324,7 +324,7 @@ const backfill = (data) => {
|
|||||||
// backfill each property
|
// backfill each property
|
||||||
Object.keys(sortedData[0].properties).forEach((key) => {
|
Object.keys(sortedData[0].properties).forEach((key) => {
|
||||||
// qualify the key (must have value)
|
// qualify the key (must have value)
|
||||||
if (Object.hasOwn(sortedData[0].properties[key], 'value')) {
|
if (Object.hasOwn(sortedData[0].properties?.[key] ?? {}, 'value')) {
|
||||||
// backfill this property
|
// backfill this property
|
||||||
result[key] = backfillProperty(sortedData, key);
|
result[key] = backfillProperty(sortedData, key);
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -1,135 +0,0 @@
|
|||||||
import Setting from './utils/setting.mjs';
|
|
||||||
import { reset as resetScroll, addScreen as addScroll, hazards } from './currentweatherscroll.mjs';
|
|
||||||
import { json } from './utils/fetch.mjs';
|
|
||||||
|
|
||||||
let firstRun = true;
|
|
||||||
|
|
||||||
const parser = new DOMParser();
|
|
||||||
|
|
||||||
// change of enable handler
|
|
||||||
const changeEnable = (newValue) => {
|
|
||||||
let newDisplay;
|
|
||||||
if (newValue) {
|
|
||||||
// add the feed to the scroll
|
|
||||||
parseFeed(customFeed.value);
|
|
||||||
// show the string box
|
|
||||||
newDisplay = 'block';
|
|
||||||
} else {
|
|
||||||
// set scroll back to original
|
|
||||||
resetScroll();
|
|
||||||
// hide the string entry
|
|
||||||
newDisplay = 'none';
|
|
||||||
}
|
|
||||||
const stringEntry = document.getElementById('settings-customFeed-label');
|
|
||||||
if (stringEntry) {
|
|
||||||
stringEntry.style.display = newDisplay;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// parse the feed/text provided
|
|
||||||
const parseFeed = (textInput) => {
|
|
||||||
// skip getting the feed on first run
|
|
||||||
if (firstRun) return;
|
|
||||||
|
|
||||||
// test validity
|
|
||||||
if (textInput === undefined || textInput === '') {
|
|
||||||
resetScroll();
|
|
||||||
}
|
|
||||||
|
|
||||||
// test for url
|
|
||||||
if (textInput.match(/https?:\/\//)) {
|
|
||||||
getFeed(textInput);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// add single text scroll after hazards if present
|
|
||||||
resetScroll();
|
|
||||||
addScroll(hazards);
|
|
||||||
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}`);
|
|
||||||
|
|
||||||
// this returns a data url
|
|
||||||
// a few sanity checks
|
|
||||||
if (rssResponse.status.content_type.indexOf('xml') < 0) return;
|
|
||||||
// determine return type
|
|
||||||
const isBase64 = rssResponse.status.content_type.substring(0, 8) !== 'text/xml';
|
|
||||||
|
|
||||||
// base 64 decode everything after the comma
|
|
||||||
const rss = isBase64 ? atob(rssResponse.contents.split('base64,')[1]) : rssResponse.contents;
|
|
||||||
|
|
||||||
// parse the rss
|
|
||||||
const doc = parser.parseFromString(rss, 'text/xml');
|
|
||||||
|
|
||||||
// get the title
|
|
||||||
const rssTitle = doc.querySelector('channel title').textContent;
|
|
||||||
|
|
||||||
// get each item
|
|
||||||
const titles = [...doc.querySelectorAll('item title')].map((t) => t.textContent);
|
|
||||||
|
|
||||||
// reset the scroll, then add the screens
|
|
||||||
resetScroll();
|
|
||||||
// add the hazards scroll first
|
|
||||||
addScroll(hazards);
|
|
||||||
titles.forEach((title) => {
|
|
||||||
// data is provided to the screen handler, so we return a function
|
|
||||||
addScroll(
|
|
||||||
() => ({
|
|
||||||
header: rssTitle,
|
|
||||||
type: 'scroll',
|
|
||||||
text: title,
|
|
||||||
}),
|
|
||||||
// false parameter does not include the default weather scrolls
|
|
||||||
false,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
// change the feed source and re-load if necessary
|
|
||||||
const changeFeed = (newValue) => {
|
|
||||||
// first pass through won't have custom feed enable ready
|
|
||||||
if (firstRun) return;
|
|
||||||
|
|
||||||
if (customFeedEnable.value) {
|
|
||||||
parseFeed(newValue);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const customFeed = new Setting('customFeed', {
|
|
||||||
name: 'Custom RSS Feed',
|
|
||||||
defaultValue: '',
|
|
||||||
type: 'string',
|
|
||||||
changeAction: changeFeed,
|
|
||||||
placeholder: 'Text or URL',
|
|
||||||
});
|
|
||||||
|
|
||||||
const customFeedEnable = new Setting('customFeedEnable', {
|
|
||||||
name: 'Enable RSS Feed/Text',
|
|
||||||
defaultValue: false,
|
|
||||||
changeAction: changeEnable,
|
|
||||||
});
|
|
||||||
|
|
||||||
// initialize the custom feed inputs on the page
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
|
||||||
// add the controls to the page
|
|
||||||
const settingsSection = document.querySelector('#settings');
|
|
||||||
settingsSection.append(customFeedEnable.generate(), customFeed.generate());
|
|
||||||
// clear the first run value
|
|
||||||
firstRun = false;
|
|
||||||
// call change enable with the current value to show/hide the url box
|
|
||||||
// and make the call to get the feed if enabled
|
|
||||||
changeEnable(customFeedEnable.value);
|
|
||||||
});
|
|
||||||
91
server/scripts/modules/custom-scroll-text.mjs
Normal file
91
server/scripts/modules/custom-scroll-text.mjs
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import Setting from './utils/setting.mjs';
|
||||||
|
import { reset as resetScroll, addScreen as addScroll, hazards } from './currentweatherscroll.mjs';
|
||||||
|
|
||||||
|
let firstRun = true;
|
||||||
|
|
||||||
|
const parser = new DOMParser();
|
||||||
|
|
||||||
|
// change of enable handler
|
||||||
|
const changeEnable = (newValue) => {
|
||||||
|
let newDisplay;
|
||||||
|
if (newValue) {
|
||||||
|
// add the text to the scroll
|
||||||
|
parseText(customText.value);
|
||||||
|
// show the string box
|
||||||
|
newDisplay = 'block';
|
||||||
|
} else {
|
||||||
|
// set scroll back to original
|
||||||
|
resetScroll();
|
||||||
|
// hide the string entry
|
||||||
|
newDisplay = 'none';
|
||||||
|
}
|
||||||
|
const stringEntry = document.getElementById('settings-customText-label');
|
||||||
|
if (stringEntry) {
|
||||||
|
stringEntry.style.display = newDisplay;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
// parse the text provided
|
||||||
|
const parseText = (textInput) => {
|
||||||
|
// skip updating text on first run
|
||||||
|
if (firstRun) return;
|
||||||
|
|
||||||
|
// test validity
|
||||||
|
if (textInput === undefined || textInput === '') {
|
||||||
|
resetScroll();
|
||||||
|
}
|
||||||
|
|
||||||
|
// split the text at pipe characters
|
||||||
|
const texts = textInput.split('|');
|
||||||
|
|
||||||
|
// add single text scroll after hazards if present
|
||||||
|
resetScroll();
|
||||||
|
addScroll(hazards);
|
||||||
|
addScroll(
|
||||||
|
() => {
|
||||||
|
// pick a random string from the available list
|
||||||
|
const randInt = Math.floor(Math.random() * texts.length);
|
||||||
|
return {
|
||||||
|
type: 'scroll',
|
||||||
|
text: texts[randInt],
|
||||||
|
};
|
||||||
|
},
|
||||||
|
// keep the existing scroll
|
||||||
|
true,
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
// change the text
|
||||||
|
const changeText = (newValue) => {
|
||||||
|
// first pass through won't have custom text enable ready
|
||||||
|
if (firstRun) return;
|
||||||
|
|
||||||
|
if (customTextEnable.value) {
|
||||||
|
parseText(newValue);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
const customText = new Setting('customText', {
|
||||||
|
name: 'Custom Text',
|
||||||
|
defaultValue: '',
|
||||||
|
type: 'string',
|
||||||
|
changeAction: changeText,
|
||||||
|
placeholder: 'Text to scroll',
|
||||||
|
});
|
||||||
|
|
||||||
|
const customTextEnable = new Setting('customTextEnable', {
|
||||||
|
name: 'Enable Custom Text',
|
||||||
|
defaultValue: false,
|
||||||
|
changeAction: changeEnable,
|
||||||
|
});
|
||||||
|
|
||||||
|
// initialize the custom text inputs on the page
|
||||||
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
|
// add the controls to the page
|
||||||
|
const settingsSection = document.querySelector('#settings');
|
||||||
|
settingsSection.append(customTextEnable.generate(), customText.generate());
|
||||||
|
// clear the first run value
|
||||||
|
firstRun = false;
|
||||||
|
// call change enable with the current value to show/hide the url box
|
||||||
|
changeEnable(customTextEnable.value);
|
||||||
|
});
|
||||||
@@ -23,7 +23,7 @@ const buildForecast = (forecast, city, cityXY) => {
|
|||||||
const getRegionalObservation = async (point, city) => {
|
const getRegionalObservation = async (point, city) => {
|
||||||
try {
|
try {
|
||||||
// get stations using centralized safe handling
|
// get stations using centralized safe handling
|
||||||
const stations = await safeJson(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/stations?limit=1`);
|
const stations = await safeJson(`https://api.weather.gov/gridpoints/${point.wfo}/${point.x},${point.y}/stations?limit=10`);
|
||||||
|
|
||||||
if (!stations || !stations.features || stations.features.length === 0) {
|
if (!stations || !stations.features || stations.features.length === 0) {
|
||||||
if (debugFlag('verbose-failures')) {
|
if (debugFlag('verbose-failures')) {
|
||||||
@@ -32,9 +32,13 @@ const getRegionalObservation = async (point, city) => {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// get the first station
|
// get the first station with a 4-letter id (generally has appropriate data)
|
||||||
const station = stations.features[0].id;
|
const station4Letter = stations.features.find((station) => {
|
||||||
const stationId = stations.features[0].properties.stationIdentifier;
|
if (station.properties.stationIdentifier.length === 4) return station.properties;
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
const station = station4Letter.id;
|
||||||
|
const stationId = station4Letter.properties.stationIdentifier;
|
||||||
// get the observation data using centralized safe handling
|
// get the observation data using centralized safe handling
|
||||||
const observation = await safeJson(`${station}/observations/latest`);
|
const observation = await safeJson(`${station}/observations/latest`);
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
<script type="module" src="scripts/modules/radar.mjs"></script>
|
<script type="module" src="scripts/modules/radar.mjs"></script>
|
||||||
<script type="module" src="scripts/modules/settings.mjs"></script>
|
<script type="module" src="scripts/modules/settings.mjs"></script>
|
||||||
<script type="module" src="scripts/modules/media.mjs"></script>
|
<script type="module" src="scripts/modules/media.mjs"></script>
|
||||||
<script type="module" src="scripts/modules/custom-rss-feed.mjs"></script>
|
<script type="module" src="scripts/modules/custom-scroll-text.mjs"></script>
|
||||||
<script type="module" src="scripts/index.mjs"></script>
|
<script type="module" src="scripts/index.mjs"></script>
|
||||||
<% } %>
|
<% } %>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user