mirror of
https://gitlab.com/vyla-entertainment/TV.git
synced 2026-11-09 17:47:20 -05:00
28 lines
1.8 KiB
JavaScript
28 lines
1.8 KiB
JavaScript
let LIB = { wl: [], fav: [] }, libK = null; const lib = $('#lib');
|
|
try { Object.assign(LIB, JSON.parse(localStorage.getItem('vyla.lib') || '{}')) } catch (e) { }
|
|
const saveLib = () => { try { localStorage.setItem('vyla.lib', JSON.stringify(LIB)) } catch (e) { } };
|
|
const slim = it => ({ id: it.id, _t: it._t || it.media_type, title: it.title, name: it.name, poster_path: it.poster_path, backdrop_path: it.backdrop_path, release_date: it.release_date, first_air_date: it.first_air_date, vote_average: it.vote_average, overview: it.overview });
|
|
const has = (k, it) => LIB[k].some(x => x.id === it.id && x._t === it._t);
|
|
function toggleLib(k, it) {
|
|
const i = LIB[k].findIndex(x => x.id === it.id && x._t === it._t), had = i >= 0;
|
|
if (had) LIB[k].splice(i, 1); else LIB[k].unshift(slim(it));
|
|
saveLib(); syncNav(); toast((had ? 'Removed from ' : 'Added to ') + LN[k]);
|
|
if (lib.classList.contains('show')) drawLib()
|
|
}
|
|
function drawLib() {
|
|
const k = libK, a = LIB[k], g = $('#lgrid');
|
|
$('#lt').innerHTML = `${LN[k]}<small>${a.length} title${a.length === 1 ? '' : 's'}</small>`;
|
|
g.innerHTML = '';
|
|
if (!a.length) { g.innerHTML = '<p class="none">Nothing here yet. Open a title, press the \u22EE button and add it.</p>'; return }
|
|
a.forEach(x => { const c = card(x, false); c._bg = x; g.appendChild(c) })
|
|
}
|
|
function openLib(k) {
|
|
libK = k; setAct(k); document.body.classList.add('lib'); lib.classList.add('show'); side.classList.remove('open'); lib.scrollTop = 0;
|
|
drawLib(); syncNav(); setFocus($('#lgrid .card') || NAVEL[k])
|
|
}
|
|
function closeLib(silent) {
|
|
if (!lib.classList.contains('show')) return;
|
|
lib.classList.remove('show'); document.body.classList.remove('lib'); libK = null; heroIt = null; bgb._u = null; syncNav();
|
|
if (!silent) { setAct(mode); setFocus($('#rows .card')) }
|
|
}
|