let sqv = '', bgT, stab = 0, SD = { q: '', all: [], mv: [], tv: [] }; const SVS = ''; const sdraw = () => { const t = $('#stext'); t.textContent = sqv || 'Search'; t.classList.toggle('q', !!sqv) }; function setQ(v) { sqv = v; sdraw(); clearTimeout(st); st = setTimeout(() => fillSearch(sqv.trim()), 300) } function sbgf(it) { clearTimeout(bgT); bgT = setTimeout(() => xf(bgb, I + 'w780' + (it.backdrop_path || it.poster_path)), 120) } async function fillSearch(q) { const my = ++sgen; skelSearch(); let all, mv, tv; const ok = x => x.poster_path && (x.media_type === 'movie' || x.media_type === 'tv'); if (q) { const d = await api('/search/multi', `&query=${encodeURIComponent(q)}&include_adult=false`); if (my !== sgen) return; all = (d.results || []).filter(ok); mv = all.filter(x => x.media_type === 'movie'); tv = all.filter(x => x.media_type === 'tv') } else { const [a, b] = await Promise.all([api('/trending/movie/week'), api('/trending/tv/week')]); if (my !== sgen) return; mv = (a.results || []).filter(x => x.poster_path).map(x => ({ ...x, media_type: 'movie' })); tv = (b.results || []).filter(x => x.poster_path).map(x => ({ ...x, media_type: 'tv' })); all = [] } SD = { q, all, mv, tv }; drawSearch() } function tile(x) { x._t = x.media_type; const e = mkf('sc', `
No results${q ? ` for \u201c${esc(q)}\u201d` : ''}
`; [...tabs.children].forEach((t, i) => t.classList.toggle('act', i === stab)); if (cur && !document.body.contains(cur)) setFocus(chips.children[1] || chips.firstChild || kb.children[2]) } ['Top Results', 'Movies', 'TV Shows'].forEach((t, i) => tabs.appendChild(mkf('tab', t, () => { stab = i; drawSearch() }))); const KL = 'abcdefghijklmnopqrstuvwxyz'.split(''), KN = "1234567890.-'&:".split(''); let num = false; function buildKb() { kb.innerHTML = ''; const mk = (label, cls, fn) => kb.appendChild(mkf('k ' + cls, label, () => { fn(); sr.scrollTo({ top: 0, behavior: 'smooth' }) })); mk(num ? 'ABC' : '123', 'w', () => { num = !num; buildKb(); setFocus(kb.firstChild) }); mk('SPACE', 'w', () => { if (sqv && !sqv.endsWith(' ')) setQ(sqv + ' ') }); (num ? KN : KL).forEach(c => mk(c, '', () => setQ(sqv + c))); mk('', 'd', () => setQ(sqv.slice(0, -1))) } buildKb(); function openSearch() { setAct('search'); document.body.classList.add('srch'); sr.classList.add('show'); side.classList.remove('open'); sr.scrollTop = 0; if (!sres.children.length) fillSearch(''); setFocus(kb.children[2]) } function closeSearch(silent) { if (!sr.classList.contains('show')) return; sr.classList.remove('show'); document.body.classList.remove('srch'); heroIt = null; bgb._u = null; if (!silent) { setAct(mode); setFocus(document.querySelector('#rows .card')) } } function skelSearch() { chips.innerHTML = SK.chips(7); sres.innerHTML = [0, 1].map(() => `