(function () { var sources = window.__PLAY_SOURCES__ || []; var video = document.getElementById('video'); var hls = null; var currentSource = 0; function play(url) { if (!url) return; if (hls) { hls.destroy(); hls = null; } if (url.indexOf('.m3u8') !== -1 && window.Hls && window.Hls.isSupported()) { hls = new Hls(); hls.loadSource(url); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED, function () { video.play().catch(function () {}); }); } else { video.src = url; video.play().catch(function () {}); } } // 切换线路 var tabs = document.querySelectorAll('.source-tab'); var groups = document.querySelectorAll('.episode-group'); tabs.forEach(function (tab) { tab.addEventListener('click', function () { tabs.forEach(function (t) { t.classList.remove('active'); }); tab.classList.add('active'); var idx = parseInt(tab.getAttribute('data-idx'), 10); currentSource = idx; groups.forEach(function (g) { g.style.display = parseInt(g.getAttribute('data-idx'), 10) === idx ? 'flex' : 'none'; }); }); }); // 点击剧集 document.querySelectorAll('.ep-btn').forEach(function (btn) { btn.addEventListener('click', function () { var url = btn.getAttribute('data-url'); play(url); }); }); // 自动播放第一集 if (sources.length && sources[0].episodes && sources[0].episodes.length) { play(sources[0].episodes[0].url); } })();