// 缓存图床 Logo
const imageCache = new Map();
function preloadImages(urls) {
urls.forEach(url => {
if (!imageCache.has(url)) {
const img = new Image();
img.src = url;
img.onload = () => imageCache.set(url, img);
img.onerror = () => console.warn(`Logo 加载失败: ${url}`);
}
});
}
// 调试信息显示
let debugTimer;
function showDebugInfo(message) {
const debugEl = document.getElementById('debugInfo');
debugEl.textContent = message;
clearTimeout(debugTimer);
debugTimer = setTimeout(() => debugEl.textContent = '', 5000);
}
// 实时时钟
function updateTime() {
const now = new Date();
document.getElementById('currentTime').textContent =
`${now.getHours().toString().padStart(2, '0')}:` +
`${now.getMinutes().toString().padStart(2, '0')}:` +
`${now.getSeconds().toString().padStart(2, '0')}`;
}
setInterval(updateTime, 1000);
updateTime();
// 获取天气
async function getWeather() {
const cacheKey = 'weather_data';
const cacheTime = 3600 * 1000;
const cached = localStorage.getItem(cacheKey);
if (cached) {
const { data, timestamp } = JSON.parse(cached);
if (Date.now() - timestamp < cacheTime) {
renderWeather(data);
return;
}
}
try {
const response = await retryFetch('https://api.kxzjoker.cn/api/Weather');
const data = await response.json();
if (data.code !== 200) throw new Error('天气获取失败');
localStorage.setItem(cacheKey, JSON.stringify({ data, timestamp: Date.now() }));
renderWeather(data);
} catch (error) {
renderWeather(null);
showDebugInfo('欢迎访问本服务');
}
}
function renderWeather(data) {
const widget = document.getElementById('weatherWidget');
widget.innerHTML = data ? `🌤️ ${data.data.tianqi.temperature}°C` : `🌤️ 未知天气`;
if (data) showDebugInfo(`👏欢迎来自${data.data.ipdata.info.split('-')[0]}的用户`);
}
// 随机文案
async function getRandomQuote() {
const cacheKey = 'random_quote';
const cacheTime = 3600 * 1000;
const cached = localStorage.getItem(cacheKey);
if (cached) {
const { text, timestamp } = JSON.parse(cached);
if (Date.now() - timestamp < cacheTime) {
document.getElementById('random-quote').textContent = text;
return;
}
}
try {
const response = await fetch('https://api.suyanw.cn/api/weimei.php?type=json');
const data = await response.json();
const text = data.text || '生活就像魔法,总有惊喜等着你!';
localStorage.setItem(cacheKey, JSON.stringify({ text, timestamp: Date.now() }));
document.getElementById('random-quote').textContent = text;
} catch (error) {
document.getElementById('random-quote').textContent = '生活就像魔法,总有惊喜等着你!';
}
}
setInterval(getRandomQuote, 30000);
getRandomQuote();
// 平台数据
const platforms = [
{ name: '抖音', url: 'https://www.douyin.com', logo: 'https://img.zlee.de/file/logo图片/1747377427291_dy.png' },
{ name: '快手', url: 'https://www.kuaishou.com', logo: 'https://img.zlee.de/file/logo图片/1747377484677_OIP-C.png' },
{ name: '火山视频', url: 'https://www.huoshan.com', logo: 'https://img.zlee.de/file/logo图片/1747377480732_hssp.png' },
{ name: '西瓜视频', url: 'https://www.ixigua.com', logo: 'https://img.zlee.de/file/logo图片/1747377479737_xgsp-black.png' },
{ name: '皮皮虾', url: 'https://www.pipix.com', logo: 'https://img.zlee.de/file/logo图片/1747377485180_ppx.png' },
{ name: '秒拍', url: 'https://www.miaopai.com', logo: 'https://img.zlee.de/file/logo图片/1747377885467_mp (1).png' },
{ name: '头条视频', url: 'https://www.toutiao.com', logo: 'https://img.zlee.de/file/logo图片/1747377883945_ttsp.png' },
{ name: '腾讯微视', url: 'https://weishi.qq.com', logo: 'https://img.zlee.de/file/logo图片/1747377891436_腾讯微视.png' },
{ name: '美图秀秀', url: 'https://www.meitu.com', logo: 'https://img.zlee.de/file/logo图片/1747377886033_mtxx.png' },
{ name: '美拍', url: 'https://www.meipai.com', logo: 'https://img.zlee.de/file/logo图片/1747377887635_mp.png' },
{ name: '微博', url: 'https://weibo.com', logo: 'https://img.zlee.de/file/logo图片/1747377888691_wb.png' },
{ name: '小红书', url: 'https://www.xiaohongshu.com', logo: 'https://img.zlee.de/file/logo图片/1747377889452_xhs.png' },
{ name: '网易云', url: 'https://music.163.com', logo: 'https://img.zlee.de/file/logo图片/1747377894287_wyy.png' }
];
// 渲染平台列表
function renderPlatforms() {
const list = document.querySelector('.platform-list');
list.innerHTML = platforms.map(p => `
${p.name}
${p.name}
${p.name}官方网站
`).join('');
validatePlatforms();
// 添加键盘导航和 Logo 预览事件
document.querySelectorAll('.platform-item').forEach(item => {
const img = item.querySelector('.platform-icon');
img.addEventListener('click', e => {
e.preventDefault();
showFullImage(img.src);
});
});
}
// 校验平台链接和图标
function validatePlatforms() {
const items = document.querySelectorAll('.platform-item');
items.forEach((item, index) => {
const expected = platforms[index];
if (item.href !== expected.url || item.querySelector('img').src !== expected.logo) {
console.warn(`平台错误: ${expected.name} (URL: ${item.href}, Logo: ${item.querySelector('img').src})`);
showDebugInfo(`警告: ${expected.name} 配置可能错误`);
}
});
}
// URL提取
function extractURL(text) {
try {
const urlRegex = /(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&\/=]*))/g;
const matches = text.match(urlRegex);
return matches ? matches[0] : null;
} catch (e) {
console.error('URL提取错误:', e);
return null;
}
}
// 剪贴板自动识别
async function checkClipboard() {
try {
if (!navigator.clipboard) return;
const text = await navigator.clipboard.readText();
const url = extractURL(text);
if (url) {
const input = document.getElementById('urlInput');
if (!input.value) {
input.value = url;
showAlert('📋 已自动填充剪贴板链接!');
}
}
} catch (error) {
console.warn('剪贴板读取失败:', error);
}
}
// 解析内容
let isParsing = false;
async function parseContent() {
if (isParsing) return;
isParsing = true;
const parseBtn = document.querySelector('.parse-btn');
parseBtn.disabled = true;
parseBtn.classList.add('parsing');
parseBtn.setAttribute('aria-busy', 'true');
showDebugInfo('开始解析流程...');
try {
const input = document.getElementById('urlInput');
if (!input) throw new Error('找不到输入框元素');
const url = extractURL(input.value);
showDebugInfo(`提取到URL: ${url || '无'}`);
if (!url) {
showAlert('🚨 请输入有效的链接哦~ (´•̥ ̯ •̥`)');
return;
}
toggleLoading(true);
showDebugInfo(`正在解析中: ${url}`);
let data, response;
try {
const apiUrl1 = `https://api.kxzjoker.cn/api/jiexi_video_2?url=${encodeURIComponent(url)}`;
response = await retryFetch(apiUrl1);
data = await response.json();
} catch (error) {
showDebugInfo('主接口失败,尝试备用接口...');
const apiUrl2 = `https://api.kxzjoker.cn/api/jiexi_video?url=${encodeURIComponent(url)}`;
response = await retryFetch(apiUrl2);
data = await response.json();
}
showDebugInfo(`收到响应状态: ${response.status}`);
if (!response.ok) {
throw new Error(`API请求失败: ${response.status} ${response.statusText}`);
}
if (!data || (data.success !== 200 && data.success !== true)) {
throw new Error('API返回数据格式异常');
}
renderContent(data.data);
saveHistory(url, data.data.title || '未命名');
input.value = '';
showDebugInfo('内容渲染完成');
} catch (error) {
console.error('解析流程错误:', error);
showDebugInfo(`错误: ${error.message}`);
const message = error.message.includes('API') ? '❌ 解析失败,服务器可能繁忙' :
error.message.includes('URL') ? '❌ 无效的链接格式' : '❌ 发生错误,请重试';
showAlert(message);
} finally {
toggleLoading(false);
parseBtn.disabled = false;
parseBtn.classList.remove('parsing');
parseBtn.setAttribute('aria-busy', 'false');
isParsing = false;
}
}
// 渲染内容
function renderContent(data) {
const contentBox = document.getElementById('contentBox');
if (!contentBox) throw new Error('找不到内容容器');
contentBox.innerHTML = '';
try {
if (data.images) {
renderImages(contentBox, data);
} else if (data.video_url) {
renderVideo(contentBox, data);
}
contentBox.style.opacity = 1;
} catch (e) {
console.error('渲染错误:', e);
showAlert('内容渲染失败,请检查数据格式');
}
}
// 渲染图片图集
function renderImages(contentBox, data) {
const galleryHTML = data.images.map((img, index) => `