Files
Paul HittandClaude Opus 5 51abf2cf26 FlameNet Classic: a 90s set-top skin for Jellyfin 10.11
CSS theme that restyles Jellyfin as a 1999-era DVR: gold selection bar,
chunky bevels, a proper grid channel guide, CRT phosphor.

Selectors were read out of a live 10.11.11 server's own shipped bundles
rather than from memory. Includes an offline preview harness that uses
Jellyfin's real DOM structure, an optional Web Audio + guide-NOW-line
extras layer, and install/rollback scripts.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-07 10:37:39 -04:00

265 lines
9.6 KiB
JavaScript

/* =============================================================================
FlameNet Classic — extras
-----------------------------------------------------------------------------
The things Custom CSS cannot do:
1. Navigation sounds — synthesised set-top "bloop"/"ding", no audio files
2. Guide NOW line — a live red time marker down the channel guide
3. Boot chime — one tone on first load
OPTIONAL. The theme is complete without this file; nothing here is required
for flamenet.css to work.
Install: see install-extras.sh (injects one <script> tag into index.html).
Toggle at runtime from the browser console:
FlameNet.sound(false) // mute (persists in localStorage)
FlameNet.sound(true) // unmute
FlameNet.nowLine(false) // hide the guide time marker
FlameNet.status() // what's on
Everything is defensive: if Jellyfin's DOM changes, features disable
themselves rather than throwing. No globals beyond `window.FlameNet`.
============================================================================= */
(function () {
'use strict';
if (window.FlameNet) return; // idempotent — double-inject is a no-op
var LS = 'flamenet.extras';
var prefs = { sound: true, nowLine: true, volume: 0.22 };
try {
var saved = JSON.parse(localStorage.getItem(LS) || '{}');
Object.keys(saved).forEach(function (k) {
if (k in prefs) prefs[k] = saved[k];
});
} catch (e) { /* corrupt or blocked storage — fall back to defaults */ }
function save() {
try { localStorage.setItem(LS, JSON.stringify(prefs)); } catch (e) {}
}
/* ---------------------------------------------------------------------------
1. SOUND
Synthesised with Web Audio — no asset files, so nothing to 404 and nothing
for a CSP to block. Two voices:
bloop : short triangle blip, for moving the selection
ding : two-tone rise, for committing to something
--------------------------------------------------------------------------- */
var ctx = null;
function audio() {
if (ctx) return ctx;
var AC = window.AudioContext || window.webkitAudioContext;
if (!AC) return null;
try { ctx = new AC(); } catch (e) { return null; }
return ctx;
}
// Browsers block audio until the user has interacted. Resume on the first
// real gesture, then stop listening.
function unlock() {
var c = audio();
if (c && c.state === 'suspended') c.resume();
window.removeEventListener('pointerdown', unlock, true);
window.removeEventListener('keydown', unlock, true);
}
window.addEventListener('pointerdown', unlock, true);
window.addEventListener('keydown', unlock, true);
function tone(freq, dur, type, delay, peak) {
var c = audio();
if (!c || c.state !== 'running') return;
var t0 = c.currentTime + (delay || 0);
var osc = c.createOscillator();
var gain = c.createGain();
osc.type = type || 'triangle';
osc.frequency.setValueAtTime(freq, t0);
// quick attack, exponential decay — the percussive set-top blip
gain.gain.setValueAtTime(0.0001, t0);
gain.gain.exponentialRampToValueAtTime(peak || prefs.volume, t0 + 0.008);
gain.gain.exponentialRampToValueAtTime(0.0001, t0 + dur);
osc.connect(gain).connect(c.destination);
osc.start(t0);
osc.stop(t0 + dur + 0.02);
}
var lastSound = 0;
function play(kind) {
if (!prefs.sound) return;
var now = Date.now();
if (now - lastSound < 45) return; // don't machine-gun on fast scrolling
lastSound = now;
if (kind === 'bloop') tone(660, 0.09, 'triangle');
else if (kind === 'ding') { tone(784, 0.10, 'triangle'); tone(1175, 0.16, 'triangle', 0.07); }
else if (kind === 'boot') { tone(523, 0.14, 'triangle'); tone(784, 0.14, 'triangle', 0.11);
tone(1047, 0.28, 'triangle', 0.22); }
}
// What counts as "moving the selection" vs "choosing something".
var NAV = '.navMenuOption, .listItem, .card, .programCell, .guide-channelHeaderCell,' +
' .alphaPickerButton, .emby-tab-button, .actionSheetMenuItem';
var GO = '.emby-button, .raised, .cardOverlayButton, .detailButton, .paper-icon-button-light';
var lastNav = null;
document.addEventListener('mouseover', function (e) {
var t = e.target.closest && e.target.closest(NAV);
if (t && t !== lastNav) { lastNav = t; play('bloop'); }
}, true);
document.addEventListener('focusin', function (e) {
var t = e.target.closest && e.target.closest(NAV);
if (t && t !== lastNav) { lastNav = t; play('bloop'); }
}, true);
document.addEventListener('click', function (e) {
if (!e.target.closest) return;
if (e.target.closest(GO) || e.target.closest(NAV)) play('ding');
}, true);
/* ---------------------------------------------------------------------------
2. GUIDE "NOW" LINE
Jellyfin's guide lays programmes out as absolutely-positioned .programCell
inside .channelPrograms, using percentage left/width across the visible time
span. We read that span off the time-slot headers and drop a red marker at
the current time. Pure overlay: nothing in the guide's own layout is touched,
so it cannot desync the channel column (see the row-pitch note in README).
--------------------------------------------------------------------------- */
var lineTimer = null;
function parseSlotTime(text) {
// ".timeslotHeader" renders localised times like "7:00 PM" or "19:00"
var m = /(\d{1,2}):(\d{2})\s*([AaPp])?/.exec(text || '');
if (!m) return null;
var h = parseInt(m[1], 10), min = parseInt(m[2], 10);
if (m[3]) {
var pm = /[Pp]/.test(m[3]);
if (h === 12) h = pm ? 12 : 0; else if (pm) h += 12;
}
return h * 60 + min;
}
function drawNowLine() {
var grid = document.querySelector('.programGrid');
var inner = document.querySelector('.timeslotHeadersInner');
var slots = document.querySelectorAll('.timeslotHeader');
if (!prefs.nowLine || !grid || !inner || slots.length < 2) {
var stale = document.getElementById('fnNowLine');
if (stale) stale.remove();
return;
}
var startMin = parseSlotTime(slots[0].textContent);
var secondMin = parseSlotTime(slots[1].textContent);
if (startMin === null || secondMin === null) return;
var step = secondMin - startMin;
if (step <= 0) step += 24 * 60; // wrapped past midnight
var spanMin = step * slots.length;
var d = new Date();
var nowMin = d.getHours() * 60 + d.getMinutes() + d.getSeconds() / 60;
var offset = nowMin - startMin;
if (offset < 0) offset += 24 * 60;
var line = document.getElementById('fnNowLine');
// outside the visible window (guide scrolled to another time) — hide it
if (offset < 0 || offset > spanMin) {
if (line) line.style.display = 'none';
return;
}
var container = grid.querySelector('.programContainer') || grid;
if (!line) {
line = document.createElement('div');
line.id = 'fnNowLine';
line.setAttribute('aria-hidden', 'true');
line.style.cssText =
'position:absolute;top:0;bottom:0;width:2px;z-index:6;pointer-events:none;' +
'background:#e0453c;box-shadow:0 0 6px 1px rgba(224,69,60,.85);';
var dot = document.createElement('div');
dot.style.cssText =
'position:absolute;top:-4px;left:-4px;width:10px;height:10px;border-radius:50%;' +
'background:#e0453c;box-shadow:0 0 6px 1px rgba(224,69,60,.85);';
line.appendChild(dot);
if (getComputedStyle(container).position === 'static') {
container.style.position = 'relative';
}
container.appendChild(line);
}
line.style.display = '';
line.style.left = (offset / spanMin * 100).toFixed(4) + '%';
}
function startNowLine() {
if (lineTimer) clearInterval(lineTimer);
lineTimer = setInterval(function () {
try { drawNowLine(); } catch (e) { /* guide gone or markup changed */ }
}, 30000);
try { drawNowLine(); } catch (e) {}
}
// Jellyfin is a SPA: the guide mounts and unmounts without a page load, so
// watch for it rather than running once.
var mo = new MutationObserver(function () {
if (document.querySelector('.programGrid')) {
try { drawNowLine(); } catch (e) {}
}
});
function boot() {
try {
mo.observe(document.body, { childList: true, subtree: true });
} catch (e) {}
startNowLine();
play('boot');
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', boot);
} else {
boot();
}
/* ---------------------------------------------------------------------------
3. PUBLIC API
--------------------------------------------------------------------------- */
window.FlameNet = {
sound: function (on) {
if (on === undefined) return prefs.sound;
prefs.sound = !!on; save();
if (prefs.sound) play('ding');
return prefs.sound;
},
volume: function (v) {
if (v === undefined) return prefs.volume;
prefs.volume = Math.max(0.01, Math.min(1, Number(v) || 0.22)); save();
play('bloop');
return prefs.volume;
},
nowLine: function (on) {
if (on === undefined) return prefs.nowLine;
prefs.nowLine = !!on; save();
try { drawNowLine(); } catch (e) {}
return prefs.nowLine;
},
status: function () {
return {
sound: prefs.sound,
volume: prefs.volume,
nowLine: prefs.nowLine,
audioContext: ctx ? ctx.state : 'not created',
guidePresent: !!document.querySelector('.programGrid')
};
},
_redraw: drawNowLine
};
})();