Skip to main content

max / makenotwork

1.6 KB · 45 lines History Blame Raw
1 function switchSectionTab(btn, panelId) {
2 document.querySelectorAll('.section-tab').forEach(function(t) { t.classList.remove('is-selected'); });
3 document.querySelectorAll('.section-panel').forEach(function(p) { p.classList.remove('active'); });
4 btn.classList.add('is-selected');
5 var panel = document.getElementById(panelId);
6 if (panel) panel.classList.add('active');
7 history.replaceState(null, '', '#' + panelId);
8 }
9
10 (function() {
11 var hash = window.location.hash.replace('#', '');
12 if (hash) {
13 var panel = document.getElementById(hash);
14 var tab = document.querySelector('[data-tab="' + hash + '"]');
15 if (panel && tab) switchSectionTab(tab, hash);
16 }
17 })();
18
19 (function() {
20 var cfg = document.getElementById('page-item-2-cfg');
21 var itemId = cfg.dataset.itemId;
22 var player = document.getElementById('item-player');
23 if (player) {
24 var loaded = false;
25 player.addEventListener('play', function loadSrc() {
26 if (!loaded) {
27 loaded = true;
28 player.pause();
29 fetch('/api/stream/' + itemId)
30 .then(function(r) {
31 if (!r.ok) throw new Error('Stream unavailable');
32 return r.json();
33 })
34 .then(function(data) {
35 player.src = data.stream_url;
36 player.play();
37 })
38 .catch(function(err) {
39 showToast(err.message || 'Could not load video');
40 });
41 }
42 }, { once: true });
43 }
44 })();
45