This commit is contained in:
4DBug
2026-08-26 18:28:49 -05:00
parent 9e93df5961
commit 145851a32e
15 changed files with 1215 additions and 272 deletions
+62 -4
View File
@@ -1,14 +1,21 @@
/*
CONFIG — where the API lives. Resolution order:
CONFIG — where the API lives + which providers to query.
API base resolution order:
1. ?api=<url> query param on any page (session override)
2. localStorage (saved from the Settings dialog)
2. localStorage (saved from Settings)
3. built-in default
Providers: until the user toggles anything in Settings, the server's own
enabled list is used. Once customized, a {name: bool} map is stored in
localStorage; names missing from the map default to enabled.
*/
(function () {
'use strict';
const DEFAULT_BASE = 'https://bug-api-test.tuns.sh';
const DEFAULT_BASE = 'https://api-tv.bug.tools';
const STORAGE_KEY = 'streamreverse.apiBase.v1';
const PROVIDER_KEY = 'streamreverse.providers.v1';
function normalize(value) {
let v = String(value || '').trim();
@@ -47,6 +54,57 @@
}
}
// null → user has not customized; caller should fall back to server defaults
function getProviders() {
try {
const raw = localStorage.getItem(PROVIDER_KEY);
if (!raw) return null;
const parsed = JSON.parse(raw);
return parsed && typeof parsed === 'object' && !Array.isArray(parsed) ? parsed : null;
} catch (e) {
return null;
}
}
function setProviders(map) {
try {
localStorage.setItem(PROVIDER_KEY, JSON.stringify(map));
} catch (e) {
/* ignore */
}
}
function clearProviders() {
try {
localStorage.removeItem(PROVIDER_KEY);
} catch (e) {
/* ignore */
}
}
// Merge the server's provider lists with the user's toggles.
// Returns the enabled provider names, in the server's `all` order.
function enabledProviders(allNames, serverEnabled) {
const all = Array.isArray(allNames) ? allNames : [];
const overrides = getProviders();
if (!overrides) {
const base = Array.isArray(serverEnabled) && serverEnabled.length ? serverEnabled : all;
return all.filter((n) => base.includes(n));
}
return all.filter((n) => overrides[n] !== false);
}
window.SR = window.SR || {};
SR.config = { DEFAULT_BASE, STORAGE_KEY, getBase, setBase, clearBase };
SR.config = {
DEFAULT_BASE,
STORAGE_KEY,
PROVIDER_KEY,
getBase,
setBase,
clearBase,
getProviders,
setProviders,
clearProviders,
enabledProviders,
};
})();