v0.1.10
build / test (push) Waiting to run

This commit is contained in:
Mateusz Gruszczyński committed 2026-11-16 22:48:34 +01:00
1 parent 052a27bc48
commit 528017b0e6
36 files changed
+3394 -216

No files matched your search

+69 -4
View File
@@ -5,6 +5,69 @@
* than English is active, every text node inserted into the DOM (and placeholder/title/
* aria-label) is translated; missing entries fall back to the English source text.
* Pattern replacements use $1..$9 for raw groups and $t1..$t9 for groups translated again. */
/* Personal settings store: localStorage on this device, mirrored to the user's profile on
* the server (GET/PUT /api/me/prefs) so language, theme and filters follow the account. */
(function () {
'use strict';
var SYNCED = ['sdvb-lang', 'sdvb-prefs', 'sdvb-chfilter', 'sdvb-group', 'sdvb-fav', 'sdvb-remind'];
var enabled = false;
function local() {
var o = {};
SYNCED.forEach(function (k) {
var v = null;
try { v = localStorage.getItem(k); } catch (e) {}
if (v !== null) o[k] = v;
});
return o;
}
function push() {
if (!enabled) return;
try {
// keepalive: a language change reloads the page right away
fetch('/api/me/prefs', { method: 'PUT', keepalive: true, credentials: 'same-origin',
headers: { 'X-Requested-With': 'simply-dvb', 'Content-Type': 'application/json' },
body: JSON.stringify(local()) }).catch(function () {});
} catch (e) {}
}
window.SDVB_STORE = {
get: function (k) { try { return localStorage.getItem(k); } catch (e) { return null; } },
set: function (k, v) {
try { localStorage.setItem(k, v); } catch (e) {}
if (SYNCED.indexOf(k) >= 0) push();
},
remove: function (k) {
try { localStorage.removeItem(k); } catch (e) {}
if (SYNCED.indexOf(k) >= 0) push();
},
/** After login: takes the profile's settings (or uploads this device's ones when the
* profile has none yet). Resolves to the list of keys that changed. */
pull: function () {
return fetch('/api/me/prefs', { credentials: 'same-origin', headers: { 'X-Requested-With': 'simply-dvb' } })
.then(function (r) { return r.ok ? r.json() : null; })
.then(function (remote) {
enabled = true;
if (!remote) return [];
var keys = Object.keys(remote).filter(function (k) { return SYNCED.indexOf(k) >= 0; });
if (!keys.length) { push(); return []; }
var changed = [];
SYNCED.forEach(function (k) {
var cur = null;
try { cur = localStorage.getItem(k); } catch (e) {}
var nv = Object.prototype.hasOwnProperty.call(remote, k) ? remote[k] : null;
if (nv !== cur) {
changed.push(k);
try { if (nv === null) localStorage.removeItem(k); else localStorage.setItem(k, nv); } catch (e) {}
}
});
return changed;
})
.catch(function () { enabled = true; return []; });
},
/** On logout: stop mirroring until the next login. */
stop: function () { enabled = false; }
};
})();
(function () {
'use strict';
@@ -127,7 +190,7 @@
});
},
setLang: function (l) {
try { localStorage.setItem(LANG_KEY, resolve(l) || DEFAULT); } catch (e) {}
window.SDVB_STORE.set(LANG_KEY, resolve(l) || DEFAULT);
location.reload();
},
/** For tooling: English keys with no translation in the given language. */
@@ -142,7 +205,7 @@
(function () {
'use strict';
var KEY = 'sdvb-prefs';
var DEFAULTS = { chartWindow: 10, theme: 'dark', accent: 'orange', density: 'comfortable', scale: 100, sidebar: 'hover', start: 'overview',
var DEFAULTS = { chartWindow: 10, theme: 'midnight', accent: 'orange', density: 'comfortable', scale: 100, sidebar: 'hover', start: 'overview',
logos: true, progress: true, autoplay: false, epgZoom: 4, clock: false, motion: true };
var ACCENTS = {
orange: ['#f69b74', '#ffb090', '#221810', '#b85b38'],
@@ -183,10 +246,12 @@
all: function () { return JSON.parse(JSON.stringify(prefs)); },
set: function (k, v) {
prefs[k] = v;
try { localStorage.setItem(KEY, JSON.stringify(prefs)); } catch (e) {}
window.SDVB_STORE.set(KEY, JSON.stringify(prefs));
apply();
},
reset: function () { try { localStorage.removeItem(KEY); } catch (e) {} load(); apply(); },
reset: function () { window.SDVB_STORE.remove(KEY); load(); apply(); },
/** Re-reads the stored values (after the profile's settings were pulled). */
reload: function () { load(); apply(); },
accents: Object.keys(ACCENTS),
accentColor: function (k) { return (ACCENTS[k] || ACCENTS.orange)[0]; }
};