Skip to content

一分钟搭建影视站,支持Docker等部署方式

重构应用程序接口处理,增强对自定义应用程序接口的支持

developer942f7cf1310c
diff --git a/css/styles.css b/css/styles.css
index 365cd89..6501198 100644
--- a/css/styles.css
+++ b/css/styles.css
@@ -88,7 +88,10 @@ button, .card-hover {
-webkit-text-fill-color: transparent;
}
+/* 改进设置面板样式 */
.settings-panel {
+ scrollbar-width: thin;
+ scrollbar-color: #444 #222;
transform: translateX(100%);
transition: transform 0.3s ease;
background: linear-gradient(135deg, var(--page-gradient-end), var(--page-gradient-start));
@@ -99,6 +102,29 @@ button, .card-hover {
transform: translateX(0);
}
+.settings-panel::-webkit-scrollbar {
+ width: 6px;
+}
+
+.settings-panel::-webkit-scrollbar-track {
+ background: transparent;
+}
+
+.settings-panel::-webkit-scrollbar-thumb {
+ background-color: #444;
+ border-radius: 4px;
+}
+
+/* 设置面板区块样式 */
+.settings-panel .shadow-inner {
+ box-shadow: inset 0 2px 4px rgba(0,0,0,0.3);
+ transition: all 0.2s ease-in-out;
+}
+
+.settings-panel .shadow-inner:hover {
+ box-shadow: inset 0 2px 8px rgba(0,0,0,0.4);
+}
+
.search-button {
background: var(--primary-color);
color: var(--text-color);
@@ -283,3 +309,292 @@ body {
#adFilterToggle:checked ~ .toggle-dot {
box-shadow: 0 2px 4px rgba(0, 204, 255, 0.3);
}
+
+/* 添加API复选框样式 */
+.form-checkbox {
+ appearance: none;
+ -webkit-appearance: none;
+ -moz-appearance: none;
+ height: 14px;
+ width: 14px;
+ background-color: #222;
+ border: 1px solid #333;
+ border-radius: 3px;
+ cursor: pointer;
+ position: relative;
+ outline: none;
+}
+
+.form-checkbox:checked {
+ background-color: var(--primary-color);
+ border-color: var(--primary-color);
+}
+
+.form-checkbox:checked::after {
+ content: '';
+ position: absolute;
+ left: 4px;
+ top: 1px;
+ width: 4px;
+ height: 8px;
+ border: solid white;
+ border-width: 0 2px 2px 0;
+ transform: rotate(45deg);
+}
+
+/* API滚动区域美化 */
+#apiCheckboxes {
+ scrollbar-width: thin;
+ scrollbar-color: #444 #222;
+}
+
+#apiCheckboxes::-webkit-scrollbar {
+ width: 6px;
+}
+
+#apiCheckboxes::-webkit-scrollbar-track {
+ background: #222;
+ border-radius: 4px;
+}
+
+#apiCheckboxes::-webkit-scrollbar-thumb {
+ background-color: #444;
+ border-radius: 4px;
+}
+
+/* 自定义API列表样式 */
+#customApisList {
+ scrollbar-width: thin;
+ scrollbar-color: #444 #222;
+}
+
+#customApisList::-webkit-scrollbar {
+ width: 6px;
+}
+
+#customApisList::-webkit-scrollbar-track {
+ background: transparent;
+}
+
+#customApisList::-webkit-scrollbar-thumb {
+ background-color: #444;
+ border-radius: 4px;
+}
+
+/* 设置面板滚动样式 */
+.settings-panel {
+ scrollbar-width: thin;
+ scrollbar-color: #444 #222;
+}
+
+.settings-panel::-webkit-scrollbar {
+ width: 6px;
+}
+
+.settings-panel::-webkit-scrollbar-track {
+ background: transparent;
+}
+
+.settings-panel::-webkit-scrollbar-thumb {
+ background-color: #444;
+ border-radius: 4px;
+}
+
+/* 添加自定义API表单动画 */
+#addCustomApiForm {
+ transition: all 0.3s ease;
+ max-height: 0;
+ opacity: 0;
+ overflow: hidden;
+}
+
+#addCustomApiForm.hidden {
+ max-height: 0;
+ padding: 0;
+ opacity: 0;
+}
+
+#addCustomApiForm:not(.hidden) {
+ max-height: 230px;
+ opacity: 1;
+}
+
+/* 成人内容API标记样式 */
+.api-adult + label {
+ color: #ff6b8b !important;
+}
+
+/* 添加警告图标和标签样式 */
+.adult-warning {
+ display: inline-flex;
+ align-items: center;
+ margin-left: 0.25rem;
+ color: #ff6b8b;
+}
+
+.adult-warning svg {
+ width: 12px;
+ height: 12px;
+ margin-right: 4px;
+}
+
+/* 过滤器禁用样式 */
+.filter-disabled {
+ opacity: 0.5;
+ pointer-events: none;
+ cursor: not-allowed;
+}
+
+/* API组标题样式 */
+.api-group-title {
+ grid-column: span 2;
+ padding: 0.25rem 0;
+ margin-top: 0.5rem;
+ border-top: 1px solid #333;
+ color: #8599b2;
+ font-size: 0.75rem;
+ text-transform: uppercase;
+ letter-spacing: 0.05em;
+}
+
+.api-group-title.adult {
+ color: #ff6b8b;
+}
+
+/* 过滤器禁用样式 - 改进版本 */
+.filter-disabled {
+ position: relative;
+}
+
+.filter-disabled::after {
+ content: '';
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background-color: rgba(0,0,0,0.4);
+ border-radius: 0.5rem;
+ z-index: 5;
+}
+
+.filter-disabled > * {
+ opacity: 0.7;
+}
+
+.filter-disabled .toggle-bg {
+ background-color: #333 !important;
+}
+
+.filter-disabled .toggle-dot {
+ transform: translateX(0) !important;
+ background-color: #666 !important;
+}
+
+/* 改进过滤器禁用样式 */
+.filter-disabled .filter-description {
+ color: #ff6b8b !important;
+ font-style: italic;
+ font-weight: 500;
+}
+
+/* 修改过滤器禁用样式,确保文字清晰可见 */
+.filter-disabled {
+ position: relative;
+}
+
+.filter-disabled::after {
+ content: '';
+ position: absolute;
+ top: 0;
+ left: 0;
+ width: 100%;
+ height: 100%;
+ background-color: rgba(0,0,0,0.3);
+ border-radius: 0.5rem;
+ z-index: 5;
+}
+
+.filter-disabled > * {
+ opacity: 1; /* 提高子元素不透明度,保证可见性 */
+ z-index: 6; /* 确保内容在遮罩上方 */
+ position: relative;
+}
+
+/* 改进过滤器禁用状态下的描述样式 */
+.filter-disabled .filter-description {
+ color: #ff7b9d !important; /* 更亮的粉色 */
+ font-style: italic;
+ font-weight: 500;
+ text-shadow: 0 0 2px rgba(0,0,0,0.8); /* 添加文字阴影提高对比度 */
+}
+
+/* 开关的禁用样式 */
+.filter-disabled .toggle-bg {
+ background-color: #444 !important;
+ opacity: 0.8;
+}
+
+.filter-disabled .toggle-dot {
+ transform: translateX(0) !important;
+ background-color: #777 !important;
+ opacity: 0.9;
+}
+
+/* 警告提示样式改进 */
+.filter-tooltip {
+ background-color: rgba(255, 61, 87, 0.1);
+ border: 1px solid rgba(255, 61, 87, 0.2);
+ border-radius: 0.25rem;
+ padding: 0.5rem;
+ margin-top: 0.5rem;
+ display: flex;
+ align-items: center;
+ font-size: 0.75rem;
+ line-height: 1.25;
+ position: relative;
+ z-index: 10;
+}
+
+.filter-tooltip svg {
+ flex-shrink: 0;
+ width: 14px;
+ height: 14px;
+ margin-right: 0.35rem;
+}
+
+/* 编辑按钮样式 */
+.custom-api-edit {
+ color: #3b82f6;
+ transition: color 0.2s ease;
+}
+
+.custom-api-edit:hover {
+ color: #2563eb;
+}
+
+/* 自定义API条目样式改进 */
+#customApisList .api-item {
+ display: flex;
+ align-items: center;
+ justify-content: space-between;
+ padding: 0.25rem 0.5rem;
+ margin-bottom: 0.25rem;
+ background-color: #222;
+ border-radius: 0.25rem;
+ transition: background-color 0.2s ease;
+}
+
+#customApisList .api-item:hover {
+ background-color: #2a2a2a;
+}
+
+/* 成人内容标签样式 */
+.adult-tag {
+ display: inline-flex;
+ align-items: center;
+ color: #ff6b8b;
+ font-size: 0.7rem;
+ font-weight: 500;
+ margin-right: 0.35rem;
+}
diff --git a/index.html b/index.html
index 4455ba7..4ec82fa 100644
--- a/index.html
+++ b/index.html
@@ -44,83 +44,95 @@
</div>
<!-- 设置面板 -->
- <div id="settingsPanel" class="settings-panel fixed right-0 top-0 h-full w-80 bg-[#111] border-l border-[#333] p-6 z-40" aria-label="设置面板" aria-hidden="true">
+ <div id="settingsPanel" class="settings-panel fixed right-0 top-0 h-full w-80 bg-[#111] border-l border-[#333] p-6 z-40 overflow-y-auto" aria-label="设置面板" aria-hidden="true">
<div class="flex justify-between items-center mb-6">
<h3 class="text-xl font-bold gradient-text">设置</h3>
<button onclick="toggleSettings()" class="text-gray-400 hover:text-white" aria-label="关闭设置">&times;</button>
</div>
- <div class="space-y-4">
- <div>
- <label class="block text-sm font-medium text-gray-400 mb-2">选择采集站点</label>
- <select id="apiSource" class="w-full bg-[#222] border border-[#333] text-white px-3 py-2 rounded-lg focus:outline-none focus:border-white transition-colors">
- <option value="aggregated">聚合搜索 (所有源)</option>
- <option value="custom">自定义接口</option>
- <option value="heimuer" selected>黑木耳影视 (heimuer)</option>
- <option value="ffzy">非凡影视 (ffzy)</option>
- <option value="tyyszy">天涯资源 (tyyszy)</option>
- <option value="zy360">360资源 (zy360)</option>
- <option value="wolong">卧龙资源 (wolong)</option>
- <option value="cjhw">新华为 (cjhw)</option>
- <option value="dbzy">豆瓣资源 (dbzy)</option>
- <option value="jisu">极速资源 (jisu)</option>
- <option value="bfzy">暴风资源 (bfzy)</option>
- <option value="mozhua">魔爪资源 (mozhua)</option>
- <option value="mdzy">魔都资源 (mdzy)</option>
- <option value="ruyi">如意资源 (ruyi)</option>
- <!-- 敏感资源站 -->
- <option value="ckzy">CK资源 (ckzy)</option>
- <option value="jkun">jkun资源 (jkun)</option>
- <option value="bwzy">百万资源 (bwzy)</option>
- <option value="souav">souav资源 (souav)</option>
- <option value="siwa">丝袜资源 (siwa)</option>
- <option value="r155">155资源 (r155)</option>
- <option value="lsb">lsb资源 (lsb)</option>
- <option value="huangcang">黄色仓库 (huangcang)</option>
- </select>
- </div>
-
- <!-- 添加自定义接口输入框 -->
- <div id="customApiInput" class="hidden">
- <label class="block text-sm font-medium text-gray-400 mb-2">自定义接口地址(可添加多个,用逗号分隔)</label>
- <input
- type="text"
- id="customApiUrl"
- class="w-full bg-[#222] border border-[#333] text-white px-3 py-2 rounded-lg focus:outline-none focus:border-white transition-colors"
- placeholder="https://example1.com,https://example2.com..."
- >
- <p class="text-xs text-gray-500 mt-1">格式: https://example1.com,https://example2.com (不含最后的斜杠)</p>
+ <div class="space-y-5">
+ <!-- 数据源设置区域 -->
+ <div class="p-3 bg-[#151515] rounded-lg shadow-inner">
+ <label class="block text-sm font-medium text-gray-400 mb-3 border-b border-[#333] pb-1">数据源设置</label>
+
+ <!-- 批量操作按钮 -->
+ <div class="flex space-x-2 mb-3">
+ <button onclick="selectAllAPIs(true)" class="px-2 py-1 bg-[#333] hover:bg-[#444] text-white text-xs rounded">全选</button>
+ <button onclick="selectAllAPIs(false)" class="px-2 py-1 bg-[#333] hover:bg-[#444] text-white text-xs rounded">全不选</button>
+ <button onclick="selectAllAPIs(true, true)" class="px-2 py-1 bg-[#333] hover:bg-[#444] text-white text-xs rounded">全选普通</button>
+ </div>
+
+ <!-- API选择区域 - 使用滚动区域 -->
+ <div class="max-h-40 overflow-y-auto bg-[#191919] p-2 rounded-lg mb-3">
+ <div id="apiCheckboxes" class="grid grid-cols-2 gap-2">
+ <!-- 这里将动态插入API复选框 -->
+ </div>
+ </div>
+
+ <!-- API信息显示 -->
+ <div class="text-xs text-gray-500 flex justify-between items-center">
+ <span>已选API数量:<span id="selectedApiCount" class="text-white">0</span></span>
+ <span id="siteStatus" class="ml-2"></span>
+ </div>
</div>
-
- <div>
- <div class="flex items-center justify-between">
- <label class="text-sm font-medium text-gray-400">黄色内容过滤</label>
- <div class="relative inline-block w-12 align-middle select-none">
- <input type="checkbox" id="yellowFilterToggle" class="opacity-0 absolute w-full h-full cursor-pointer z-10">
- <div class="toggle-bg bg-[#333] w-12 h-6 rounded-full transition-colors duration-300 ease-in-out"></div>
- <div class="toggle-dot absolute w-5 h-5 bg-white rounded-full top-0.5 left-0.5 transition-transform duration-300 ease-in-out"></div>
+
+ <!-- 自定义API管理区域 -->
+ <div class="p-3 bg-[#151515] rounded-lg shadow-inner">
+ <div class="flex justify-between items-center mb-2">
+ <label class="block text-sm font-medium text-gray-400 border-b border-[#333] w-full pb-1">自定义API</label>
+ <button onclick="showAddCustomApiForm()" class="bg-[#333] hover:bg-[#444] text-white w-6 h-6 rounded-full text-center leading-none text-lg ml-1">+</button>
+ </div>
+ <div id="customApisList" class="max-h-32 overflow-y-auto mb-2">
+ <!-- 自定义API将显示在这里 -->
+ </div>
+
+ <!-- 添加自定义API表单 (默认隐藏) -->
+ <div id="addCustomApiForm" class="hidden mt-2 p-2 bg-[#191919] rounded-lg">
+ <input type="text" id="customApiName" placeholder="API名称" class="w-full bg-[#222] border border-[#333] text-white px-2 py-1 rounded mb-2">
+ <input type="text" id="customApiUrl" placeholder="API链接 (例如: https://example.com)" class="w-full bg-[#222] border border-[#333] text-white px-2 py-1 rounded mb-2">
+ <!-- 添加成人内容切换 -->
+ <div class="flex items-center mb-2">
+ <input type="checkbox" id="customApiIsAdult" class="form-checkbox h-4 w-4 text-pink-500 bg-[#222] border border-[#333]">
+ <label for="customApiIsAdult" class="ml-2 text-xs text-pink-400">黄色资源站</label>
+ </div>
+ <div class="flex space-x-2">
+ <button onclick="addCustomApi()" class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded text-xs">添加</button>
+ <button onclick="cancelAddCustomApi()" class="bg-[#444] hover:bg-[#555] text-white px-3 py-1 rounded text-xs">取消</button>
</div>
</div>
- <p class="text-xs text-gray-500 mt-1">过滤"伦理片"等成人内容</p>
</div>
- <!-- 添加广告过滤开关 -->
- <div>
+ <!-- 内容过滤设置区域 -->
+ <div class="p-3 bg-[#151515] rounded-lg shadow-inner">
+ <label class="block text-sm font-medium text-gray-400 mb-3 border-b border-[#333] pb-1">内容过滤</label>
+
+ <!-- 黄色内容过滤开关 -->
+ <div class="flex flex-col mb-3 pb-3 border-b border-[#222] relative">
+ <div class="flex items-center justify-between">
+ <div>
+ <label class="text-sm font-medium text-gray-400">黄色内容过滤</label>
+ <p class="text-xs text-gray-500 mt-1 filter-description">过滤"伦理片"等黄色内容</p>
+ </div>
+ <div class="relative inline-block w-12 align-middle select-none">
+ <input type="checkbox" id="yellowFilterToggle" class="opacity-0 absolute w-full h-full cursor-pointer z-10">
+ <div class="toggle-bg bg-[#333] w-12 h-6 rounded-full transition-colors duration-300 ease-in-out"></div>
+ <div class="toggle-dot absolute w-5 h-5 bg-white rounded-full top-0.5 left-0.5 transition-transform duration-300 ease-in-out"></div>
+ </div>
+ </div>
+ <!-- 警告提示将在这里动态插入 -->
+ </div>
+
+ <!-- 广告过滤开关 -->
<div class="flex items-center justify-between">
- <label class="text-sm font-medium text-gray-400">分片广告过滤</label>
+ <div>
+ <label class="text-sm font-medium text-gray-400">分片广告过滤</label>
+ <p class="text-xs text-gray-500 mt-1">关闭可减少旧版浏览器卡顿</p>
+ </div>
<div class="relative inline-block w-12 align-middle select-none">
<input type="checkbox" id="adFilterToggle" class="opacity-0 absolute w-full h-full cursor-pointer z-10">
<div class="toggle-bg bg-[#333] w-12 h-6 rounded-full transition-colors duration-300 ease-in-out"></div>
<div class="toggle-dot absolute w-5 h-5 bg-white rounded-full top-0.5 left-0.5 transition-transform duration-300 ease-in-out"></div>
</div>
</div>
- <p class="text-xs text-gray-500 mt-1">关闭可减少旧版浏览器播放卡顿问题</p>
- </div>
-
- <div class="mt-4">
- <p class="text-xs text-gray-500">当前站点代码:
- <span id="currentCode" class="text-white"></span>
- <span id="siteStatus" class="ml-2"></span>
- </p>
</div>
</div>
</div>
diff --git a/js/api.js b/js/api.js
index c4cc25d..b2cf2a0 100644
--- a/js/api.js
+++ b/js/api.js
@@ -2,7 +2,6 @@
async function handleApiRequest(url) {
const customApi = url.searchParams.get('customApi') || '';
const source = url.searchParams.get('source') || 'heimuer';
- const multipleApis = url.searchParams.get('multipleApis') === 'true';
try {
if (url.pathname === '/api/search') {
@@ -16,20 +15,10 @@ async function handleApiRequest(url) {
throw new Error('使用自定义API时必须提供API地址');
}
- if (!API_SITES[source] && source !== 'custom' && source !== 'aggregated') {
+ if (!API_SITES[source] && source !== 'custom') {
throw new Error('无效的API来源');
}
- // 处理聚合搜索
- if (source === 'aggregated') {
- return await handleAggregatedSearch(searchQuery);
- }
-
- // 处理多个自定义API搜索
- if (source === 'custom' && multipleApis && customApi.includes(CUSTOM_API_CONFIG.separator)) {
- return await handleMultipleCustomSearch(searchQuery, customApi);
- }
-
const apiUrl = customApi
? `${customApi}${API_CONFIG.search.path}${encodeURIComponent(searchQuery)}`
: `${API_SITES[source].api}${API_CONFIG.search.path}${encodeURIComponent(searchQuery)}`;
@@ -77,7 +66,7 @@ async function handleApiRequest(url) {
}
}
- // 聚合搜索的详情处理 - 需要根据存储在数据中的源信息获取
+ // 详情处理
if (url.pathname === '/api/detail') {
const id = url.searchParams.get('id');
const sourceCode = url.searchParams.get('source') || 'heimuer'; // 获取源代码
@@ -105,6 +94,11 @@ async function handleApiRequest(url) {
return await handleSpecialSourceDetail(id, sourceCode);
}
+ // 如果是自定义API,并且传递了detail参数,尝试特殊处理
+ if (sourceCode === 'custom' && url.searchParams.get('useDetail') === 'true') {
+ return await handleCustomApiSpecialDetail(id, customApi);
+ }
+
const detailUrl = customApi
? `${customApi}${API_CONFIG.detail.path}${id}`
: `${API_SITES[sourceCode].api}${API_CONFIG.detail.path}${id}`;
@@ -125,7 +119,7 @@ async function handleApiRequest(url) {
throw new Error(`详情请求失败: ${response.status}`);
}
- // 由于现在返回的是JSON而不是HTML,我们需要解析JSON
+ // 解析JSON
const data = await response.json();
// 检查返回的数据是否有效
@@ -167,7 +161,6 @@ async function handleApiRequest(url) {
code: 200,
episodes: episodes,
detailUrl: detailUrl,
- // 添加更多视频详情,以便前端展示
videoInfo: {
title: videoDetail.vod_name,
cover: videoDetail.vod_pic,
@@ -201,21 +194,81 @@ async function handleApiRequest(url) {
}
}
-// 处理极速资源详情的特殊函数 - 类似非凡影视的处理方式
+// 处理自定义API的特殊详情页
+async function handleCustomApiSpecialDetail(id, customApi) {
+ try {
+ // 构建详情页URL
+ const detailUrl = `${customApi}/index.php/vod/detail/id/${id}.html`;
+
+ // 添加超时处理
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), 10000);
+
+ // 获取详情页HTML
+ const response = await fetch(PROXY_URL + encodeURIComponent(detailUrl), {
+ headers: {
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36',
+ },
+ signal: controller.signal
+ });
+
+ clearTimeout(timeoutId);
+
+ if (!response.ok) {
+ throw new Error(`自定义API详情页请求失败: ${response.status}`);
+ }
+
+ // 获取HTML内容
+ const html = await response.text();
+
+ // 使用通用模式提取m3u8链接
+ const generalPattern = /\$(https?:\/\/[^"'\s]+?\.m3u8)/g;
+ let matches = html.match(generalPattern) || [];
+
+ // 处理链接
+ matches = matches.map(link => {
+ link = link.substring(1, link.length);
+ const parenIndex = link.indexOf('(');
+ return parenIndex > 0 ? link.substring(0, parenIndex) : link;
+ });
+
+ // 提取基本信息
+ const titleMatch = html.match(/<h1[^>]*>([^<]+)<\/h1>/);
+ const titleText = titleMatch ? titleMatch[1].trim() : '';
+
+ const descMatch = html.match(/<div[^>]*class=["']sketch["'][^>]*>([\s\S]*?)<\/div>/);
+ const descText = descMatch ? descMatch[1].replace(/<[^>]+>/g, ' ').trim() : '';
+
+ return JSON.stringify({
+ code: 200,
+ episodes: matches,
+ detailUrl: detailUrl,
+ videoInfo: {
+ title: titleText,
+ desc: descText,
+ source_name: '自定义源',
+ source_code: 'custom'
+ }
+ });
+ } catch (error) {
+ console.error(`自定义API详情获取失败:`, error);
+ throw error;
+ }
+}
+// 处理极速资源详情的特殊函数
async function handleJisuDetail(id, sourceCode) {
// 直接复用通用的特殊源处理函数,传入相应参数
return await handleSpecialSourceDetail(id, sourceCode);
}
-// 添加: 处理非凡影视详情的特殊函数
+// 处理非凡影视详情的特殊函数
async function handleFFZYDetail(id, sourceCode) {
// 直接复用通用的特殊源处理函数,传入相应参数
return await handleSpecialSourceDetail(id, sourceCode);
}
-// 通用特殊源详情处理函数
-
+// 通用特殊源详情处理函数
async function handleSpecialSourceDetail(id, sourceCode) {
try {
// 构建详情页URL(使用配置中的detail URL而不是api URL)
@@ -288,7 +341,7 @@ async function handleSpecialSourceDetail(id, sourceCode) {
}
}
-// 处理聚合搜索
+// 处理聚合搜索
async function handleAggregatedSearch(searchQuery) {
// 获取可用的API源列表(排除aggregated和custom)
const availableSources = Object.keys(API_SITES).filter(key =>
@@ -530,22 +583,10 @@ async function handleMultipleCustomSearch(searchQuery, customApiUrls) {
};
})();
-async function testSiteAvailability(source) {
+async function testSiteAvailability(apiUrl) {
try {
- // 避免传递空的自定义URL
- const apiParams = source === 'custom' && customApiUrl
- ? '&customApi=' + encodeURIComponent(customApiUrl)
- : source === 'custom'
- ? '' // 如果是custom但没有URL,返回空字符串
- : '&source=' + source;
-
- // 如果是custom但没有URL,直接返回false
- if (source === 'custom' && !customApiUrl) {
- return false;
- }
-
// 使用更简单的测试查询
- const response = await fetch('/api/search?wd=test' + apiParams, {
+ const response = await fetch('/api/search?wd=test&customApi=' + encodeURIComponent(apiUrl), {
// 添加超时
signal: AbortSignal.timeout(5000)
});
diff --git a/js/app.js b/js/app.js
index e2845ff..910f191 100644
--- a/js/app.js
+++ b/js/app.js
@@ -1,6 +1,7 @@
// 全局变量
-let currentApiSource = localStorage.getItem('currentApiSource') || 'heimuer';
-let customApiUrl = localStorage.getItem('customApiUrl') || '';
+let selectedAPIs = JSON.parse(localStorage.getItem('selectedAPIs') || '["heimuer"]'); // 默认选中黑木耳
+let customAPIs = JSON.parse(localStorage.getItem('customAPIs') || '[]'); // 存储自定义API列表
+
// 添加当前播放的集数索引
let currentEpisodeIndex = 0;
// 添加当前视频的所有集数
@@ -10,37 +11,34 @@ let currentVideoTitle = '';
// 全局变量用于倒序状态
let episodesReversed = false;
-// 解析多个自定义API源
-let customApiUrls = [];
-function parseCustomApiUrls() {
- if (!customApiUrl) return [];
- return customApiUrl.split(CUSTOM_API_CONFIG.separator)
- .map(url => url.trim())
- .filter(url => url.length > 0)
- .slice(0, CUSTOM_API_CONFIG.maxSources);
-}
-
// 页面初始化
document.addEventListener('DOMContentLoaded', function() {
- // 初始化时检查是否使用自定义接口
- if (currentApiSource === 'custom') {
- document.getElementById('customApiInput').classList.remove('hidden');
- document.getElementById('customApiUrl').value = customApiUrl;
- customApiUrls = parseCustomApiUrls();
- }
-
- // 设置 select 的默认选中值
- document.getElementById('apiSource').value = currentApiSource;
-
- // 初始化显示当前站点代码
- document.getElementById('currentCode').textContent = currentApiSource;
+ // 初始化API复选框
+ initAPICheckboxes();
+
+ // 初始化自定义API列表
+ renderCustomAPIsList();
- // 初始化显示当前站点状态(使用优化后的测试函数)
- updateSiteStatusWithTest(currentApiSource);
+ // 初始化显示选中的API数量
+ updateSelectedApiCount();
// 渲染搜索历史
renderSearchHistory();
+ // 设置默认API选择(如果是第一次加载)
+ if (!localStorage.getItem('hasInitializedDefaults')) {
+ // 仅选择黑木耳源
+ selectedAPIs = ["heimuer"];
+ localStorage.setItem('selectedAPIs', JSON.stringify(selectedAPIs));
+
+ // 默认选中过滤开关
+ localStorage.setItem('yellowFilterEnabled', 'true');
+ localStorage.setItem(PLAYER_CONFIG.adFilteringStorage, 'true');
+
+ // 标记已初始化默认值
+ localStorage.setItem('hasInitializedDefaults', 'true');
+ }
+
// 设置黄色内容过滤开关初始状态
const yellowFilterToggle = document.getElementById('yellowFilterToggle');
if (yellowFilterToggle) {
@@ -55,185 +53,453 @@ document.addEventListener('DOMContentLoaded', function() {
// 设置事件监听器
setupEventListeners();
+
+ // 初始检查成人API选中状态
+ setTimeout(checkAdultAPIsSelected, 100);
});
-// 带有超时和缓存的站点可用性测试
-async function updateSiteStatusWithTest(source) {
- // 显示加载状态
- document.getElementById('siteStatus').innerHTML = '<span class="text-gray-500">●</span> 测试中...';
-
- // 自定义API源特殊处理 - 测试所有提供的API
- if (source === 'custom') {
- const urls = parseCustomApiUrls();
- if (urls.length === 0) {
- updateSiteStatus(false);
- document.getElementById('siteStatus').innerHTML = '<span class="text-gray-500">●</span> 未设置API';
- return;
+// 初始化API复选框
+function initAPICheckboxes() {
+ const container = document.getElementById('apiCheckboxes');
+ container.innerHTML = '';
+
+ // 添加普通API组标题
+ const normalTitle = document.createElement('div');
+ normalTitle.className = 'api-group-title';
+ normalTitle.textContent = '普通资源';
+ container.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 = `
+ <input type="checkbox" id="api_${apiKey}"
+ class="form-checkbox h-3 w-3 text-blue-600 bg-[#222] border border-[#333]"
+ ${checked ? 'checked' : ''}
+ data-api="${apiKey}">
+ <label for="api_${apiKey}" class="ml-1 text-xs text-gray-400 truncate">${api.name}</label>
+ `;
+ container.appendChild(checkbox);
+
+ // 添加事件监听器
+ checkbox.querySelector('input').addEventListener('change', function() {
+ updateSelectedAPIs();
+ checkAdultAPIsSelected();
+ });
+ });
+
+ // 添加成人API组标题
+ const adultTitle = document.createElement('div');
+ adultTitle.className = 'api-group-title adult';
+ adultTitle.innerHTML = `黄色资源采集站 <span class="adult-warning">
+ <svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor">
+ <path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" />
+ </svg>
+ </span>`;
+ container.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 = `
+ <input type="checkbox" id="api_${apiKey}"
+ class="form-checkbox h-3 w-3 text-blue-600 bg-[#222] border border-[#333] api-adult"
+ ${checked ? 'checked' : ''}
+ data-api="${apiKey}">
+ <label for="api_${apiKey}" class="ml-1 text-xs text-pink-400 truncate">${api.name}</label>
+ `;
+ container.appendChild(checkbox);
+
+ // 添加事件监听器
+ checkbox.querySelector('input').addEventListener('change', function() {
+ updateSelectedAPIs();
+ checkAdultAPIsSelected();
+ });
+ });
+
+ // 初始检查成人内容状态
+ checkAdultAPIsSelected();
+}
+
+// 检查是否有成人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 = '<strong class="text-pink-300">选中黄色资源站时无法启用此过滤</strong>';
}
- // 测试所有API并返回可用的数量
- const results = await Promise.all(
- urls.map(url => testCustomApiUrl(url))
- );
+ // 移除提示信息(如果存在)
+ const existingTooltip = yellowFilterContainer.querySelector('.filter-tooltip');
+ if (existingTooltip) {
+ existingTooltip.remove();
+ }
+ } else {
+ // 启用黄色内容过滤器
+ yellowFilterToggle.disabled = false;
+ yellowFilterContainer.classList.remove('filter-disabled');
+
+ // 恢复原来的描述文字
+ if (filterDescription) {
+ filterDescription.innerHTML = '过滤"伦理片"等黄色内容';
+ }
- const availableCount = results.filter(r => r).length;
- if (availableCount > 0) {
- updateSiteStatus(true);
- document.getElementById('siteStatus').innerHTML =
- `<span class="text-green-500">●</span> ${availableCount}/${urls.length} 可用`;
- } else {
- updateSiteStatus(false);
- document.getElementById('siteStatus').innerHTML =
- `<span class="text-red-500">●</span> 全部不可用`;
+ // 移除提示信息
+ const existingTooltip = yellowFilterContainer.querySelector('.filter-tooltip');
+ if (existingTooltip) {
+ existingTooltip.remove();
}
- return;
}
+}
+
+// 渲染自定义API列表
+function renderCustomAPIsList() {
+ const container = document.getElementById('customApisList');
+ if (!container) return;
- // 检查缓存中是否有有效的测试结果
- const cacheKey = `siteStatus_${source}_${customApiUrl || ''}`;
- const cachedResult = localStorage.getItem(cacheKey);
-
- if (cachedResult) {
- try {
- const { isAvailable, timestamp } = JSON.parse(cachedResult);
- // 缓存有效期为2个月
- if (Date.now() - timestamp < 5184000000) {
- updateSiteStatus(isAvailable);
- return;
- }
- } catch (e) {
- // 忽略解析错误,继续测试
- console.error('缓存数据解析错误:', e);
- }
+ if (customAPIs.length === 0) {
+ container.innerHTML = '<p class="text-xs text-gray-500 text-center my-2">未添加自定义API</p>';
+ return;
}
- // 使用 Promise.race 添加超时处理
- try {
- const timeoutPromise = new Promise((_, reject) =>
- setTimeout(() => reject(new Error('测试超时')), 8000)
- );
-
- const testPromise = testSiteAvailability(source);
- const isAvailable = await Promise.race([testPromise, timeoutPromise]);
-
- // 更新UI状态
- updateSiteStatus(isAvailable);
+ 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';
+
+ // 将(18+)标记移到最前面
+ const adultTag = api.isAdult ? '<span class="text-xs text-pink-400 mr-1">(18+)</span>' : '';
+
+ apiItem.innerHTML = `
+ <div class="flex items-center flex-1 min-w-0">
+ <input type="checkbox" id="custom_api_${index}"
+ class="form-checkbox h-3 w-3 text-blue-600 mr-1 ${api.isAdult ? 'api-adult' : ''}"
+ ${selectedAPIs.includes('custom_' + index) ? 'checked' : ''}
+ data-custom-index="${index}">
+ <div class="flex-1 min-w-0">
+ <div class="text-xs font-medium ${textColorClass} truncate">
+ ${adultTag}${api.name}
+ </div>
+ <div class="text-xs text-gray-500 truncate">${api.url}</div>
+ </div>
+ </div>
+ <div class="flex items-center">
+ <button class="text-blue-500 hover:text-blue-700 text-xs px-1" onclick="editCustomApi(${index})">✎</button>
+ <button class="text-red-500 hover:text-red-700 text-xs px-1" onclick="removeCustomApi(${index})">✕</button>
+ </div>
+ `;
+ container.appendChild(apiItem);
- // 缓存测试结果
- localStorage.setItem(cacheKey, JSON.stringify({
- isAvailable,
- timestamp: Date.now()
- }));
- } catch (error) {
- console.error('站点测试错误:', error);
- updateSiteStatus(false);
+ // 添加事件监听器
+ apiItem.querySelector('input').addEventListener('change', function() {
+ updateSelectedAPIs();
+ checkAdultAPIsSelected();
+ });
+ });
+}
+
+// 编辑自定义API
+function editCustomApi(index) {
+ if (index < 0 || index >= customAPIs.length) return;
+
+ const api = customAPIs[index];
+
+ // 填充表单数据
+ const nameInput = document.getElementById('customApiName');
+ const urlInput = document.getElementById('customApiUrl');
+ const isAdultInput = document.getElementById('customApiIsAdult');
+
+ nameInput.value = api.name;
+ urlInput.value = api.url;
+ if (isAdultInput) isAdultInput.checked = api.isAdult || false;
+
+ // 显示表单
+ const form = document.getElementById('addCustomApiForm');
+ if (form) {
+ form.classList.remove('hidden');
+
+ // 替换表单按钮操作
+ const buttonContainer = form.querySelector('div:last-child');
+ buttonContainer.innerHTML = `
+ <button onclick="updateCustomApi(${index})" class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded text-xs">更新</button>
+ <button onclick="cancelEditCustomApi()" class="bg-[#444] hover:bg-[#555] text-white px-3 py-1 rounded text-xs">取消</button>
+ `;
}
}
-// 测试单个自定义API URL
-async function testCustomApiUrl(url) {
- if (!url) return false;
+// 更新自定义API
+function updateCustomApi(index) {
+ if (index < 0 || index >= customAPIs.length) return;
+
+ const nameInput = document.getElementById('customApiName');
+ const urlInput = document.getElementById('customApiUrl');
+ const isAdultInput = document.getElementById('customApiIsAdult');
- // 验证URL格式
- if (CUSTOM_API_CONFIG.validateUrl && !/^https?:\/\/.+/.test(url)) {
- return false;
+ const name = nameInput.value.trim();
+ let url = urlInput.value.trim();
+ const isAdult = isAdultInput ? isAdultInput.checked : false;
+
+ if (!name || !url) {
+ showToast('请输入API名称和链接', 'warning');
+ return;
}
- // 检查缓存
- if (CUSTOM_API_CONFIG.cacheResults) {
- const cacheKey = `api_test_${url}`;
- const cachedResult = localStorage.getItem(cacheKey);
- if (cachedResult) {
- try {
- const { isAvailable, timestamp } = JSON.parse(cachedResult);
- if (Date.now() - timestamp < CUSTOM_API_CONFIG.cacheExpiry) {
- return isAvailable;
- }
- } catch (e) {
- console.error('缓存解析错误:', e);
- }
- }
+ // 确保URL格式正确
+ if (!/^https?:\/\/.+/.test(url)) {
+ showToast('API链接格式不正确,需以http://或https://开头', 'warning');
+ return;
}
- try {
- const controller = new AbortController();
- const timeoutId = setTimeout(
- () => controller.abort(),
- CUSTOM_API_CONFIG.testTimeout
- );
-
- // 使用wd=test为参数进行简单搜索测试
- const response = await fetch('/api/search?wd=test&customApi=' + encodeURIComponent(url), {
- signal: controller.signal
- });
-
- clearTimeout(timeoutId);
-
- const result = response.ok;
-
- // 缓存结果
- if (CUSTOM_API_CONFIG.cacheResults) {
- localStorage.setItem(`api_test_${url}`, JSON.stringify({
- isAvailable: result,
- timestamp: Date.now()
- }));
- }
-
- return result;
- } catch (e) {
- console.error(`自定义API测试失败(${url}):`, e);
- return false;
+ // 移除URL末尾的斜杠
+ if (url.endsWith('/')) {
+ url = url.slice(0, -1);
}
+
+ // 更新API信息
+ customAPIs[index] = { name, url, isAdult };
+ localStorage.setItem('customAPIs', JSON.stringify(customAPIs));
+
+ // 重新渲染自定义API列表
+ renderCustomAPIsList();
+
+ // 重新检查成人API选中状态
+ checkAdultAPIsSelected();
+
+ // 恢复添加按钮
+ restoreAddCustomApiButtons();
+
+ // 清空表单并隐藏
+ nameInput.value = '';
+ urlInput.value = '';
+ if (isAdultInput) isAdultInput.checked = false;
+ document.getElementById('addCustomApiForm').classList.add('hidden');
+
+ showToast('已更新自定义API: ' + name, 'success');
}
-// 设置事件监听器
-function setupEventListeners() {
- // API源选择变更事件
- document.getElementById('apiSource').addEventListener('change', async function(e) {
- currentApiSource = e.target.value;
- const customApiInput = document.getElementById('customApiInput');
-
- if (currentApiSource === 'custom') {
- customApiInput.classList.remove('hidden');
- customApiUrl = document.getElementById('customApiUrl').value;
- localStorage.setItem('customApiUrl', customApiUrl);
- customApiUrls = parseCustomApiUrls();
- // 自定义接口不立即测试可用性
- document.getElementById('siteStatus').innerHTML = '<span class="text-gray-500">●</span> 待测试';
+// 取消编辑自定义API
+function cancelEditCustomApi() {
+ // 清空表单
+ document.getElementById('customApiName').value = '';
+ document.getElementById('customApiUrl').value = '';
+ const isAdultInput = document.getElementById('customApiIsAdult');
+ if (isAdultInput) isAdultInput.checked = false;
+
+ // 隐藏表单
+ document.getElementById('addCustomApiForm').classList.add('hidden');
+
+ // 恢复添加按钮
+ restoreAddCustomApiButtons();
+}
+
+// 恢复自定义API添加按钮
+function restoreAddCustomApiButtons() {
+ const form = document.getElementById('addCustomApiForm');
+ const buttonContainer = form.querySelector('div:last-child');
+ buttonContainer.innerHTML = `
+ <button onclick="addCustomApi()" class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded text-xs">添加</button>
+ <button onclick="cancelAddCustomApi()" class="bg-[#444] hover:bg-[#555] text-white px-3 py-1 rounded text-xs">取消</button>
+ `;
+}
+
+// 更新选中的API列表
+function updateSelectedAPIs() {
+ // 获取所有内置API复选框
+ const builtInApiCheckboxes = document.querySelectorAll('#apiCheckboxes input:checked');
+
+ // 获取选中的内置API
+ const builtInApis = Array.from(builtInApiCheckboxes).map(input => input.dataset.api);
+
+ // 获取选中的自定义API
+ const customApiCheckboxes = document.querySelectorAll('#customApisList input:checked');
+ const customApiIndices = Array.from(customApiCheckboxes).map(input => 'custom_' + input.dataset.customIndex);
+
+ // 合并内置和自定义API
+ selectedAPIs = [...builtInApis, ...customApiIndices];
+
+ // 保存到localStorage
+ localStorage.setItem('selectedAPIs', JSON.stringify(selectedAPIs));
+
+ // 更新显示选中的API数量
+ updateSelectedApiCount();
+}
+
+// 更新选中的API数量显示
+function updateSelectedApiCount() {
+ const countEl = document.getElementById('selectedApiCount');
+ if (countEl) {
+ countEl.textContent = selectedAPIs.length;
+ }
+}
+
+// 全选或取消全选API
+function selectAllAPIs(selectAll = true, excludeAdult = false) {
+ const checkboxes = document.querySelectorAll('#apiCheckboxes input[type="checkbox"]');
+
+ checkboxes.forEach(checkbox => {
+ if (excludeAdult && checkbox.classList.contains('api-adult')) {
+ checkbox.checked = false;
} else {
- customApiInput.classList.add('hidden');
- // 非自定义接口立即测试可用性
- showToast('正在测试站点可用性...', 'info');
- updateSiteStatusWithTest(currentApiSource);
+ checkbox.checked = selectAll;
}
-
- localStorage.setItem('currentApiSource', currentApiSource);
- document.getElementById('currentCode').textContent = currentApiSource;
-
- // 清理搜索结果并重置搜索区域
- resetSearchArea();
});
+
+ updateSelectedAPIs();
+ checkAdultAPIsSelected();
+}
- // 自定义接口输入框事件 - 更新为支持多个API
- document.getElementById('customApiUrl').addEventListener('blur', async function(e) {
- customApiUrl = e.target.value;
- localStorage.setItem('customApiUrl', customApiUrl);
-
- if (currentApiSource === 'custom' && customApiUrl) {
- showToast('正在测试API可用性...', 'info');
- customApiUrls = parseCustomApiUrls();
-
- // 测试所有配置的API
- if (customApiUrls.length > 0) {
- updateSiteStatusWithTest('custom');
- } else {
- document.getElementById('siteStatus').innerHTML =
- '<span class="text-gray-500">●</span> 未设置API';
- showToast('请输入至少一个有效的API地址', 'warning');
+// 显示添加自定义API表单
+function showAddCustomApiForm() {
+ const form = document.getElementById('addCustomApiForm');
+ if (form) {
+ form.classList.remove('hidden');
+ }
+}
+
+// 取消添加自定义API - 修改函数来重用恢复按钮逻辑
+function cancelAddCustomApi() {
+ const form = document.getElementById('addCustomApiForm');
+ if (form) {
+ form.classList.add('hidden');
+ document.getElementById('customApiName').value = '';
+ document.getElementById('customApiUrl').value = '';
+ const isAdultInput = document.getElementById('customApiIsAdult');
+ if (isAdultInput) isAdultInput.checked = false;
+
+ // 确保按钮是添加按钮
+ restoreAddCustomApiButtons();
+ }
+}
+
+// 添加自定义API
+function addCustomApi() {
+ const nameInput = document.getElementById('customApiName');
+ const urlInput = document.getElementById('customApiUrl');
+ const isAdultInput = document.getElementById('customApiIsAdult');
+
+ const name = nameInput.value.trim();
+ let url = urlInput.value.trim();
+ const isAdult = isAdultInput ? isAdultInput.checked : false;
+
+ if (!name || !url) {
+ showToast('请输入API名称和链接', 'warning');
+ return;
+ }
+
+ // 确保URL格式正确
+ if (!/^https?:\/\/.+/.test(url)) {
+ showToast('API链接格式不正确,需以http://或https://开头', 'warning');
+ return;
+ }
+
+ // 移除URL末尾的斜杠
+ if (url.endsWith('/')) {
+ url = url.slice(0, -1);
+ }
+
+ // 添加到自定义API列表 - 增加isAdult属性
+ customAPIs.push({ name, url, isAdult });
+ localStorage.setItem('customAPIs', JSON.stringify(customAPIs));
+
+ // 默认选中新添加的API
+ const newApiIndex = customAPIs.length - 1;
+ selectedAPIs.push('custom_' + newApiIndex);
+ localStorage.setItem('selectedAPIs', JSON.stringify(selectedAPIs));
+
+ // 重新渲染自定义API列表
+ renderCustomAPIsList();
+
+ // 更新选中的API数量
+ updateSelectedApiCount();
+
+ // 重新检查成人API选中状态
+ checkAdultAPIsSelected();
+
+ // 清空表单并隐藏
+ nameInput.value = '';
+ urlInput.value = '';
+ if (isAdultInput) isAdultInput.checked = false;
+ document.getElementById('addCustomApiForm').classList.add('hidden');
+
+ showToast('已添加自定义API: ' + name, 'success');
+}
+
+// 移除自定义API
+function removeCustomApi(index) {
+ if (index < 0 || index >= customAPIs.length) return;
+
+ const apiName = customAPIs[index].name;
+
+ // 从列表中移除API
+ customAPIs.splice(index, 1);
+ localStorage.setItem('customAPIs', JSON.stringify(customAPIs));
+
+ // 从选中列表中移除此API
+ const customApiId = 'custom_' + index;
+ selectedAPIs = selectedAPIs.filter(id => id !== customApiId);
+
+ // 更新大于此索引的自定义API索引
+ selectedAPIs = selectedAPIs.map(id => {
+ if (id.startsWith('custom_')) {
+ const currentIndex = parseInt(id.replace('custom_', ''));
+ if (currentIndex > index) {
+ return 'custom_' + (currentIndex - 1);
}
}
+ return id;
});
+
+ localStorage.setItem('selectedAPIs', JSON.stringify(selectedAPIs));
+
+ // 重新渲染自定义API列表
+ renderCustomAPIsList();
+
+ // 更新选中的API数量
+ updateSelectedApiCount();
+
+ // 重新检查成人API选中状态
+ checkAdultAPIsSelected();
+
+ showToast('已移除自定义API: ' + apiName, 'info');
+}
+// 设置事件监听器
+function setupEventListeners() {
// 回车搜索
document.getElementById('searchInput').addEventListener('keypress', function(e) {
if (e.key === 'Enter') {
@@ -286,7 +552,16 @@ function resetSearchArea() {
}
}
-// 搜索功能
+// 获取自定义API信息
+function getCustomApiInfo(customApiIndex) {
+ const index = parseInt(customApiIndex);
+ if (isNaN(index) || index < 0 || index >= customAPIs.length) {
+ return null;
+ }
+ return customAPIs[index];
+}
+
+// 搜索功能 - 修改为支持多选API
async function search() {
const query = document.getElementById('searchInput').value.trim();
@@ -295,64 +570,83 @@ async function search() {
return;
}
+ if (selectedAPIs.length === 0) {
+ showToast('请至少选择一个API源', 'warning');
+ return;
+ }
+
showLoading();
try {
- let apiParams;
+ // 保存搜索历史
+ saveSearchHistory(query);
- // 处理自定义API源
- if (currentApiSource === 'custom') {
- // 获取可能包含多个API的字符串
- customApiUrl = document.getElementById('customApiUrl').value.trim();
- localStorage.setItem('customApiUrl', customApiUrl);
-
- if (!customApiUrl) {
- showToast('请先设置自定义API地址', 'warning');
- hideLoading();
- return;
- }
-
- // 检查是否有多个API (存在逗号)
- if (customApiUrl.includes(CUSTOM_API_CONFIG.separator)) {
- apiParams = '&customApi=' + encodeURIComponent(customApiUrl) + '&source=custom&multipleApis=true';
- } else {
- apiParams = '&customApi=' + encodeURIComponent(customApiUrl) + '&source=custom';
+ // 从所有选中的API源搜索
+ let allResults = [];
+ const searchPromises = selectedAPIs.map(async (apiId) => {
+ try {
+ let apiUrl, apiName;
+
+ // 处理自定义API
+ if (apiId.startsWith('custom_')) {
+ const customIndex = apiId.replace('custom_', '');
+ const customApi = getCustomApiInfo(customIndex);
+ if (!customApi) return [];
+
+ apiUrl = customApi.url + API_CONFIG.search.path + encodeURIComponent(query);
+ apiName = customApi.name;
+ } else {
+ // 内置API
+ if (!API_SITES[apiId]) return [];
+ apiUrl = API_SITES[apiId].api + API_CONFIG.search.path + encodeURIComponent(query);
+ apiName = API_SITES[apiId].name;
+ }
+
+ // 添加超时处理
+ const controller = new AbortController();
+ const timeoutId = setTimeout(() => controller.abort(), 8000);
+
+ const response = await fetch(PROXY_URL + encodeURIComponent(apiUrl), {
+ headers: API_CONFIG.search.headers,
+ signal: controller.signal
+ });
+
+ clearTimeout(timeoutId);
+
+ if (!response.ok) {
+ return [];
+ }
+
+ const data = await response.json();
+
+ if (!data || !data.list || !Array.isArray(data.list) || data.list.length === 0) {
+ return [];
+ }
+
+ // 添加源信息到每个结果
+ const results = data.list.map(item => ({
+ ...item,
+ source_name: apiName,
+ source_code: apiId,
+ api_url: apiId.startsWith('custom_') ? getCustomApiInfo(apiId.replace('custom_', ''))?.url : undefined
+ }));
+
+ return results;
+ } catch (error) {
+ console.warn(`API ${apiId} 搜索失败:`, error);
+ return [];
}
- } else {
- apiParams = '&source=' + currentApiSource;
- }
-
- // 添加超时处理
- const controller = new AbortController();
- const timeoutId = setTimeout(() => controller.abort(), 15000);
-
- const response = await fetch('/api/search?wd=' + encodeURIComponent(query) + apiParams, {
- signal: controller.signal
});
- clearTimeout(timeoutId);
-
- const data = await response.json();
-
- if (data.code === 400) {
- showToast(data.msg || '搜索失败,请检查网络连接或更换数据源', 'error');
- hideLoading();
- return;
- }
-
- // 保存搜索历史
- saveSearchHistory(query);
+ // 等待所有搜索请求完成
+ const resultsArray = await Promise.all(searchPromises);
- // 处理搜索结果过滤:如果启用了黄色内容过滤,则过滤掉分类含有"伦理片"或"色情片"的项目
- const yellowFilterEnabled = localStorage.getItem('yellowFilterEnabled') === 'true';
- let results = data.list;
- if (yellowFilterEnabled) {
- const banned = ['伦理片','门事件','国产传媒','cosplay','黑丝诱惑','无码','日本无码','有码','日本有码','SWAG','网红主播', '色情片','同性片','福利视频','福利片'];
- results = results.filter(item => {
- const typeName = item.type_name || '';
- return !banned.some(keyword => typeName.includes(keyword));
- });
- }
+ // 合并所有结果
+ resultsArray.forEach(results => {
+ if (Array.isArray(results) && results.length > 0) {
+ allResults = allResults.concat(results);
+ }
+ });
// 显示结果区域,调整搜索区域
document.getElementById('searchArea').classList.remove('flex-1');
@@ -362,7 +656,7 @@ async function search() {
const resultsDiv = document.getElementById('results');
// 如果没有结果
- if (!results || results.length === 0) {
+ if (!allResults || allResults.length === 0) {
resultsDiv.innerHTML = `
<div class="col-span-full text-center py-16">
<svg class="mx-auto h-12 w-12 text-gray-500" fill="none" viewBox="0 0 24 24" stroke="currentColor">
@@ -377,8 +671,19 @@ async function search() {
return;
}
+ // 处理搜索结果过滤:如果启用了黄色内容过滤,则过滤掉分类含有敏感内容的项目
+ const yellowFilterEnabled = localStorage.getItem('yellowFilterEnabled') === 'true';
+ if (yellowFilterEnabled) {
+ const banned = ['伦理片','门事件','萝莉少女','制服诱惑','国产传媒','cosplay','黑丝诱惑','无码','日本无码','有码','日本有码','SWAG','网红主播', '色情片','同性片','福利视频','福利片'];
+ allResults = allResults.filter(item => {
+ const typeName = item.type_name || '';
+ return !banned.some(keyword => typeName.includes(keyword));
+ });
+ }
+
// 添加XSS保护,使用textContent和属性转义
- resultsDiv.innerHTML = results.map(item => {
+ resultsDiv.innerHTML = allResults.map(item => {
+ // ...existing code for rendering results...
const safeId = item.vod_id ? item.vod_id.toString().replace(/[^\w-]/g, '') : '';
const safeName = (item.vod_name || '').toString()
.replace(/</g, '&lt;')
@@ -386,7 +691,7 @@ async function search() {
.replace(/"/g, '&quot;');
const sourceInfo = item.source_name ?
`<span class="bg-[#222] text-xs px-2 py-1 rounded-full">${item.source_name}</span>` : '';
- const sourceCode = item.source_code || currentApiSource;
+ const sourceCode = item.source_code || '';
// 添加API URL属性,用于详情获取
const apiUrlAttr = item.api_url ?
@@ -395,12 +700,10 @@ async function search() {
// 重新设计的卡片布局 - 支持更好的封面图显示
const hasCover = item.vod_pic && item.vod_pic.startsWith('http');
- // 不同的布局设计 - 桌面端使用横向布局,减小卡片尺寸
return `
<div class="card-hover bg-[#111] rounded-lg overflow-hidden cursor-pointer transition-all hover:scale-[1.02] h-full"
onclick="showDetails('${safeId}','${safeName}','${sourceCode}')" ${apiUrlAttr}>
<div class="md:flex">
- <!-- 封面图区域 - 调整高度更紧凑 -->
${hasCover ? `
<div class="md:w-1/4 relative overflow-hidden">
<div class="w-full h-40 md:h-full">
@@ -412,12 +715,10 @@ async function search() {
</div>
</div>` : ''}
- <!-- 内容区域 - 调整为适应多行标题 -->
<div class="p-3 flex flex-col flex-grow ${hasCover ? 'md:w-3/4' : 'w-full'}">
<div class="flex-grow">
<h3 class="text-lg font-semibold mb-2 break-words">${safeName}</h3>
- <!-- 添加影片元数据 - 使用原始彩色标签样式,但减小间距 -->
<div class="flex flex-wrap gap-1 mb-2">
${(item.type_name || '').toString().replace(/</g, '&lt;') ?
`<span class="text-xs py-0.5 px-1.5 rounded bg-opacity-20 bg-blue-500 text-blue-300">
@@ -433,7 +734,6 @@ async function search() {
</p>
</div>
- <!-- 底部元信息区域 - 减小上边距 -->
<div class="flex justify-between items-center mt-2 pt-2 border-t border-gray-800">
${sourceInfo ? `<div>${sourceInfo}</div>` : '<div></div>'}
<div>
@@ -463,8 +763,8 @@ async function search() {
}
}
-// 显示详情 - 修改函数接受sourceCode参数和API URL
-async function showDetails(id, vod_name, sourceCode = currentApiSource) {
+// 显示详情 - 修改为支持自定义API
+async function showDetails(id, vod_name, sourceCode) {
if (!id) {
showToast('视频ID无效', 'error');
return;
@@ -475,27 +775,19 @@ async function showDetails(id, vod_name, sourceCode = currentApiSource) {
// 构建API参数
let apiParams = '';
- // 处理自定义API源 - 如果有api_url参数,优先使用
- if (sourceCode === 'custom') {
- // 查找结果中包含api_url的项目
- const apiUrl = event.currentTarget?.getAttribute('data-api-url');
-
- if (apiUrl) {
- apiParams = '&customApi=' + encodeURIComponent(apiUrl);
- } else {
- // 回退到使用第一个可用的自定义API
- const urls = parseCustomApiUrls();
- if (urls.length > 0) {
- apiParams = '&customApi=' + encodeURIComponent(urls[0]);
- } else {
- showToast('无可用的自定义API', 'error');
- hideLoading();
- return;
- }
+ // 处理自定义API源
+ if (sourceCode.startsWith('custom_')) {
+ const customIndex = sourceCode.replace('custom_', '');
+ const customApi = getCustomApiInfo(customIndex);
+ if (!customApi) {
+ showToast('自定义API配置无效', 'error');
+ hideLoading();
+ return;
}
- apiParams += '&source=custom';
+ apiParams = '&customApi=' + encodeURIComponent(customApi.url) + '&source=custom';
} else {
+ // 内置API
apiParams = '&source=' + sourceCode;
}
@@ -503,6 +795,7 @@ async function showDetails(id, vod_name, sourceCode = currentApiSource) {
const data = await response.json();
+ // ...existing code for showing details...
const modal = document.getElementById('modal');
const modalTitle = document.getElementById('modalTitle');
const modalContent = document.getElementById('modalContent');
@@ -515,9 +808,6 @@ async function showDetails(id, vod_name, sourceCode = currentApiSource) {
modalTitle.innerHTML = `<span class="break-words">${vod_name || '未知视频'}</span>${sourceName}`;
currentVideoTitle = vod_name || '未知视频';
- // 保存当前源码以便后续操作
- currentApiSource = sourceCode;
-
if (data.episodes && data.episodes.length > 0) {
// 安全处理集数URL
const safeEpisodes = data.episodes.map(url => {
@@ -554,11 +844,7 @@ async function showDetails(id, vod_name, sourceCode = currentApiSource) {
modal.classList.remove('hidden');
} catch (error) {
console.error('获取详情错误:', error);
- if (error.name === 'AbortError') {
- showToast('获取详情超时,请检查网络连接', 'error');
- } else {
- showToast('获取详情失败,请稍后重试', 'error');
- }
+ showToast('获取详情失败,请稍后重试', 'error');
} finally {
hideLoading();
}
diff --git a/js/config.js b/js/config.js
index 3c2aee1..0f3c03e 100644
--- a/js/config.js
+++ b/js/config.js
@@ -187,5 +187,6 @@ const CUSTOM_API_CONFIG = {
namePrefix: 'Custom-', // 自定义源名称前缀
validateUrl: true, // 验证URL格式
cacheResults: true, // 缓存测试结果
- cacheExpiry: 5184000000 // 缓存过期时间(2个月)
+ cacheExpiry: 5184000000, // 缓存过期时间(2个月)
+ adultPropName: 'isAdult' // 用于标记成人内容的属性名
};