screentinker/Examples/PIP-CAP-AU-Alert-Monitor/overlay.js
screentinker 0b138f10c6
Add PiP overlay example recipes (#132)
Self-contained examples for the PiP overlay API (POST /api/pip), each
with a CSP-safe query-param overlay (external JS), config.example.json,
zero runtime deps, an offline test, and a README:

- PIP-Announce-Broadcast    manual one-shot message to a screen/group
- PIP-Weather-Widget        Open-Meteo current conditions (keyless)
- PIP-Air-Quality           Open-Meteo US AQI widget (keyless)
- PIP-Crypto-Ticker         CoinGecko price strip (keyless)
- PIP-News-Ticker           scrolling RSS/Atom headlines
- PIP-Room-Status-Calendar  ICS-driven Available/Busy room sign
- PIP-Event-Countdown       client-side countdown, auto-clears at zero
- PIP-Welcome-Board         rotating welcome/birthday cards from CSV
- PIP-Fundraiser-Thermometer goal-progress bar from local/URL JSON
- PIP-QR-Rotator            rotating QR codes, encoded client-side
- PIP-Incident-Webhook      event-driven: red on firing, clear on resolved

Also includes the CAP-AU (NSW RFS) and US NWS/NOAA emergency-alert
monitors that push expiry-aware PiP overlays.

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 20:20:37 -05:00

29 lines
1.2 KiB
JavaScript

// External overlay script — same-origin so the server CSP (scriptSrc 'self') permits it.
// Reads the alert fields from the URL query string and populates the card.
(function () {
var q = new URLSearchParams(location.search);
var get = function (k) { return (q.get(k) || '').trim(); };
var color = '#' + (get('color').replace(/[^0-9a-fA-F]/g, '') || 'CC0000');
document.getElementById('band').style.background = color;
document.getElementById('level').textContent = (get('level') || 'Alert').toUpperCase();
document.getElementById('headline').textContent = get('headline') || 'Emergency alert in your area';
var meta = [];
if (get('area')) meta.push('<b>Area:</b> ' + escapeHtml(get('area')));
if (get('status')) meta.push('<b>Status:</b> ' + escapeHtml(get('status')));
document.getElementById('meta').innerHTML = meta.join('');
var updated = get('updated');
if (updated) {
var d = new Date(updated);
document.getElementById('updated').textContent = isNaN(d) ? ('· ' + updated) : ('· updated ' + d.toLocaleString('en-AU'));
}
function escapeHtml(s) {
return s.replace(/[&<>"']/g, function (c) {
return { '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;', "'": '&#39;' }[c];
});
}
})();