// 全局变量 let selectedAPIs = JSON.parse(localStorage.getItem('selectedAPIs') || '["tyyszy","dyttzy", "bfzy", "ruyi"]'); // 默认选中资源 let customAPIs = JSON.parse(localStorage.getItem('customAPIs') || '[]'); // 存储自定义API列表 // 添加当前播放的集数索引 let currentEpisodeIndex = 0; // 添加当前视频的所有集数 let currentEpisodes = []; // 添加当前视频的标题 let currentVideoTitle = ''; // 全局变量用于倒序状态 let episodesReversed = false; // 页面初始化 document.addEventListener('DOMContentLoaded', function () { // 初始化API复选框 initAPICheckboxes(); // 初始化自定义API列表 renderCustomAPIsList(); // 初始化显示选中的API数量 updateSelectedApiCount(); // 渲染搜索历史 renderSearchHistory(); // 设置默认API选择(如果是第一次加载) if (!localStorage.getItem('hasInitializedDefaults')) { // 默认选中资源 selectedAPIs = ["tyyszy", "bfzy", "dyttzy", "ruyi"]; localStorage.setItem('selectedAPIs', JSON.stringify(selectedAPIs)); // 默认选中过滤开关 localStorage.setItem('yellowFilterEnabled', 'true'); localStorage.setItem(PLAYER_CONFIG.adFilteringStorage, 'true'); // 默认启用豆瓣功能 localStorage.setItem('doubanEnabled', 'true'); // 标记已初始化默认值 localStorage.setItem('hasInitializedDefaults', 'true'); } // 设置黄色内容过滤器开关初始状态 const yellowFilterToggle = document.getElementById('yellowFilterToggle'); if (yellowFilterToggle) { yellowFilterToggle.checked = localStorage.getItem('yellowFilterEnabled') === 'true'; } // 设置广告过滤开关初始状态 const adFilterToggle = document.getElementById('adFilterToggle'); if (adFilterToggle) { adFilterToggle.checked = localStorage.getItem(PLAYER_CONFIG.adFilteringStorage) !== 'false'; // 默认为true } // 设置事件监听器 setupEventListeners(); // 初始检查成人API选中状态 setTimeout(checkAdultAPIsSelected, 100); }); // 初始化API复选框 function initAPICheckboxes() { const container = document.getElementById('apiCheckboxes'); container.innerHTML = ''; // 添加普通API组标题 const normaldiv = document.createElement('div'); normaldiv.id = 'normaldiv'; normaldiv.className = 'grid grid-cols-2 gap-2'; const normalTitle = document.createElement('div'); normalTitle.className = 'api-group-title'; normalTitle.textContent = '普通资源'; normaldiv.appendChild(normalTitle); // 创建普通API源的复选框 Object.keys(API_SITES).forEach(apiKey => { const api = API_SITES[apiKey]; if (api.adult) return; // 跳过成人内容API,稍后添加 const checked = selectedAPIs.includes(apiKey); const checkbox = document.createElement('div'); checkbox.className = 'flex items-center'; checkbox.innerHTML = ` `; normaldiv.appendChild(checkbox); // 添加事件监听器 checkbox.querySelector('input').addEventListener('change', function () { updateSelectedAPIs(); checkAdultAPIsSelected(); }); }); container.appendChild(normaldiv); // 添加成人API列表 addAdultAPI(); // 初始检查成人内容状态 checkAdultAPIsSelected(); } // 添加成人API列表 function addAdultAPI() { // 仅在隐藏设置为false时添加成人API组 if (!HIDE_BUILTIN_ADULT_APIS && (localStorage.getItem('yellowFilterEnabled') === 'false')) { const container = document.getElementById('apiCheckboxes'); // 添加成人API组标题 const adultdiv = document.createElement('div'); adultdiv.id = 'adultdiv'; adultdiv.className = 'grid grid-cols-2 gap-2'; const adultTitle = document.createElement('div'); adultTitle.className = 'api-group-title adult'; adultTitle.innerHTML = `黄色资源采集站 `; adultdiv.appendChild(adultTitle); // 创建成人API源的复选框 Object.keys(API_SITES).forEach(apiKey => { const api = API_SITES[apiKey]; if (!api.adult) return; // 仅添加成人内容API const checked = selectedAPIs.includes(apiKey); const checkbox = document.createElement('div'); checkbox.className = 'flex items-center'; checkbox.innerHTML = ` `; adultdiv.appendChild(checkbox); // 添加事件监听器 checkbox.querySelector('input').addEventListener('change', function () { updateSelectedAPIs(); checkAdultAPIsSelected(); }); }); container.appendChild(adultdiv); } } // 检查是否有成人API被选中 function checkAdultAPIsSelected() { // 查找所有内置成人API复选框 const adultBuiltinCheckboxes = document.querySelectorAll('#apiCheckboxes .api-adult:checked'); // 查找所有自定义成人API复选框 const customApiCheckboxes = document.querySelectorAll('#customApisList .api-adult:checked'); const hasAdultSelected = adultBuiltinCheckboxes.length > 0 || customApiCheckboxes.length > 0; const yellowFilterToggle = document.getElementById('yellowFilterToggle'); const yellowFilterContainer = yellowFilterToggle.closest('div').parentNode; const filterDescription = yellowFilterContainer.querySelector('p.filter-description'); // 如果选择了成人API,禁用黄色内容过滤器 if (hasAdultSelected) { yellowFilterToggle.checked = false; yellowFilterToggle.disabled = true; localStorage.setItem('yellowFilterEnabled', 'false'); // 添加禁用样式 yellowFilterContainer.classList.add('filter-disabled'); // 修改描述文字 if (filterDescription) { filterDescription.innerHTML = '选中黄色资源站时无法启用此过滤'; } // 移除提示信息(如果存在) const existingTooltip = yellowFilterContainer.querySelector('.filter-tooltip'); if (existingTooltip) { existingTooltip.remove(); } } else { // 启用黄色内容过滤器 yellowFilterToggle.disabled = false; yellowFilterContainer.classList.remove('filter-disabled'); // 恢复原来的描述文字 if (filterDescription) { filterDescription.innerHTML = '过滤"伦理片"等黄色内容'; } // 移除提示信息 const existingTooltip = yellowFilterContainer.querySelector('.filter-tooltip'); if (existingTooltip) { existingTooltip.remove(); } } } // 渲染自定义API列表 function renderCustomAPIsList() { const container = document.getElementById('customApisList'); if (!container) return; if (customAPIs.length === 0) { container.innerHTML = '
未添加自定义API
'; return; } container.innerHTML = ''; customAPIs.forEach((api, index) => { const apiItem = document.createElement('div'); apiItem.className = 'flex items-center justify-between p-1 mb-1 bg-[#222] rounded'; const textColorClass = api.isAdult ? 'text-pink-400' : 'text-white'; const adultTag = api.isAdult ? '(18+)' : ''; // 新增 detail 地址显示 const detailLine = api.detail ? `请尝试其他关键词或更换数据源
${(item.vod_remarks || '暂无介绍').toString().replace(/
简介:
${descriptionText}