79 lines
2.7 KiB
JavaScript
79 lines
2.7 KiB
JavaScript
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 = `
|
|
// <div class="swiper-slide" style="max-height:10rem">
|
|
// <a href="${ad.href}" target="_blank">
|
|
// <img src="${ad.img}" style="display: block;width:100%;max-height:10rem" alt="">
|
|
// </a>
|
|
// </div>
|
|
// `;
|
|
// 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 += `<li class='top-line'>
|
|
<a href='${json[i].vod_url}' title='${json[i].vod_name}'>
|
|
<span class='pull-right text-red'>${json[i].vod_part}</span>
|
|
${json[i].vod_name}
|
|
</a>
|
|
</li>`;
|
|
}
|
|
} else {
|
|
list = "<p style='padding: 80px 0; text-align: center'>您还没有看过影片哦</p>";
|
|
}
|
|
|
|
$("#stui_history").html(list);
|
|
|
|
// 清空历史记录
|
|
$(".historyclean").on("click", function () {
|
|
localStorage.removeItem("recente");
|
|
$("#stui_history").html("<p style='padding: 80px 0; text-align: center'>您还没有看过影片哦</p>");
|
|
});
|
|
}
|
|
}
|
|
|
|
// 添加新历史记录
|
|
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));
|
|
}
|
|
|
|
|
|
|