('expanded'); b.textContent = 'Show less'; } } // Load real-time view count (bypasses page cache) (function() { var vc = document.getElementById('viewCount'); if (vc) { var vid = vc.getAttribute('data-vid'); if (vid) { // Increment hit and get updated count fetch('/api_hits.php?id=' + encodeURIComponent(vid) + '&action=hit') .then(function(r) { return r.json(); }) .then(function(data) { if (data.code === 1) { vc.textContent = data.hits.toLocaleString() + ' views'; } }) .catch(function() {}); } } })(); // Load real-time like/dislike counts (bypasses page cache) (function() { var btnLikeEl = document.getElementById('btnLike'); if (btnLikeEl) { var vodId = btnLikeEl.getAttribute('data-id'); if (vodId) { fetch('/index.php/ajax/digg?id=' + vodId + '&mid=1') .then(function(r) { return r.json(); }) .then(function(data) { if (data.code === 1 && data.data) { var lc = document.getElementById('likeCount'); var dc = document.getElementById('dislikeCount'); if (lc) lc.textContent = data.data.up; if (dc) dc.textContent = data.data.down; } }) .catch(function() {}); } } })(); // Like/Dislike functionality (function() { var btnLike = document.getElementById('btnLike'); var btnDislike = document.getElementById('btnDislike'); var likeCount = document.getElementById('likeCount'); var dislikeCount = document.getElementById('dislikeCount'); var toast = document.getElementById('toast'); function showToast(msg) { toast.textContent = msg; toast.style.display = 'block'; setTimeout(function(){ toast.style.display = 'none'; }, 2000); } function doDigg(type) { var id = btnLike.getAttribute('data-id'); fetch('/index.php/ajax/digg?id=' + id + '&mid=1&type=' + type) .then(function(r) { return r.json(); }) .then(function(data) { if (data.code === 1) { likeCount.textContent = data.data.up; dislikeCount.textContent = data.data.down; showToast(type === 'up' ? 'Liked!' : 'Disliked!'); } else if (data.code === 1002) { showToast('You already voted!'); } else { showToast(data.msg || 'Error'); } }) .catch(function() { showToast('Network error'); }); } if (btnLike) { btnLike.addEventListener('click', function() { doDigg('up'); }); } if (btnDislike) { btnDislike.addEventListener('click', function() { doDigg('down'); }); } })();