document.addEventListener("DOMContentLoaded", function () { // setTimeout(function () { // if (CctvTopHf && CctvTopHf.length > 0) { // var CctvTopHfDom = document.querySelector('.cctv-hf-list-top .swiper-wrapper '); // 获取容器元素 // // 遍历数组并生成 HTML // CctvTopHf.forEach(function (ad) { // var html = ` //
// `; // CctvTopHfDom.innerHTML += html; // 将 HTML 添加到容器中 // }); // } // }, 1500) }); function history() { if ($("#stui_history").length) { let historyData = localStorage.getItem("recente"); let list = ""; if (historyData) { let json = JSON.parse(historyData); console.log("本地存储数据:", json); for (let i = 0; i < json.length; i++) { list += `您还没有看过影片哦
"; } $("#stui_history").html(list); // 清空历史记录 $(".historyclean").on("click", function () { localStorage.removeItem("recente"); $("#stui_history").html("您还没有看过影片哦
"); }); } } // 添加新历史记录 function addHistory(vod_name, vod_url, vod_part) { let historyData = localStorage.getItem("recente"); let historyList = historyData ? JSON.parse(historyData) : []; // 查找是否已有该视频 let index = historyList.findIndex(item => item.vod_name === vod_name); if (index !== -1) { // 如果已存在,更新集数 historyList[index].vod_part = vod_part; historyList[index].vod_url = vod_url; // 可能最新观看的是其他来源 } else { // 追加新记录(最多存 10 条) if (historyList.length >= 10) { historyList.shift(); // 移除最早的一条 } historyList.push({ vod_name, vod_url, vod_part }); } localStorage.setItem("recente", JSON.stringify(historyList)); }