Update script.js
Browse files
script.js
CHANGED
|
@@ -644,6 +644,146 @@ document.addEventListener('DOMContentLoaded', function() {
|
|
| 644 |
console.warn('JSZip 未加载!打包下载功能不可用');
|
| 645 |
showDebugInfo('警告:打包下载需要 JSZip 库支持');
|
| 646 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 647 |
|
| 648 |
setInterval(updateTime, 1000);
|
| 649 |
updateTime();
|
|
|
|
| 644 |
console.warn('JSZip 未加载!打包下载功能不可用');
|
| 645 |
showDebugInfo('警告:打包下载需要 JSZip 库支持');
|
| 646 |
}
|
| 647 |
+
unction extractDouyinVariant(text) {
|
| 648 |
+
const re = /(https?:\/\/v\.douyin\.com\/[^\s]+)(?:\s+\d{2}\/\d{2})?/i;
|
| 649 |
+
const m = text.match(re);
|
| 650 |
+
if (!m) return null;
|
| 651 |
+
return {
|
| 652 |
+
displayUrl: m[0], // 完整变体,用于 UI 展示
|
| 653 |
+
cleanUrl: m[1] // 纯短链,用于调用接口
|
| 654 |
+
};
|
| 655 |
+
}
|
| 656 |
+
|
| 657 |
+
// —— 2. 修复粘贴按钮 ——
|
| 658 |
+
document.getElementById('clipboard-btn').addEventListener('click', async () => {
|
| 659 |
+
const videoUrlInput = document.getElementById('urlInput');
|
| 660 |
+
try {
|
| 661 |
+
const text = await navigator.clipboard.readText();
|
| 662 |
+
if (!text) throw new Error('剪贴板为空');
|
| 663 |
+
videoUrlInput.value = text;
|
| 664 |
+
const variant = extractDouyinVariant(text);
|
| 665 |
+
if (variant) {
|
| 666 |
+
showDebugInfo(`已提取:${variant.displayUrl}`);
|
| 667 |
+
parseContent(variant.cleanUrl);
|
| 668 |
+
} else {
|
| 669 |
+
showAlert('未检测到有效的短链,请检查复制的内容');
|
| 670 |
+
}
|
| 671 |
+
} catch (err) {
|
| 672 |
+
console.warn('读取剪贴板失败', err);
|
| 673 |
+
showAlert('无法访问剪贴板,请手动粘贴链接');
|
| 674 |
+
videoUrlInput.focus();
|
| 675 |
+
}
|
| 676 |
+
});
|
| 677 |
+
|
| 678 |
+
// —— 3. “解析”按钮 & 回车 同样使用新提取 ——
|
| 679 |
+
document.getElementById('parse-btn').addEventListener('click', () => {
|
| 680 |
+
const raw = document.getElementById('urlInput').value.trim();
|
| 681 |
+
const variant = extractDouyinVariant(raw);
|
| 682 |
+
if (variant) {
|
| 683 |
+
showDebugInfo(`调用接口:${variant.cleanUrl}`);
|
| 684 |
+
parseContent(variant.cleanUrl);
|
| 685 |
+
} else {
|
| 686 |
+
showAlert('请输入或粘贴有效的抖音短链');
|
| 687 |
+
}
|
| 688 |
+
});
|
| 689 |
+
document.getElementById('urlInput').addEventListener('keypress', e => {
|
| 690 |
+
if (e.key === 'Enter') {
|
| 691 |
+
const raw = e.target.value.trim();
|
| 692 |
+
const variant = extractDouyinVariant(raw);
|
| 693 |
+
if (variant) parseContent(variant.cleanUrl);
|
| 694 |
+
else showAlert('请输入或粘贴有效的抖音短链');
|
| 695 |
+
}
|
| 696 |
+
});
|
| 697 |
+
|
| 698 |
+
// —— 4. 修改 parseContent 接口调用,直接用 cleanUrl ——
|
| 699 |
+
async function parseContent(cleanUrl) {
|
| 700 |
+
if (isParsing) return;
|
| 701 |
+
isParsing = true;
|
| 702 |
+
toggleLoading(true);
|
| 703 |
+
try {
|
| 704 |
+
showDebugInfo(`开始解析:${cleanUrl}`);
|
| 705 |
+
const apiUrl = `https://api.kxzjoker.cn/api/jiexi_video?url=${encodeURIComponent(cleanUrl)}`;
|
| 706 |
+
const resp = await fetch(apiUrl);
|
| 707 |
+
const data = await resp.json();
|
| 708 |
+
if (!data.success) throw new Error(data.message || '解析失败');
|
| 709 |
+
renderContent(data.data);
|
| 710 |
+
saveToHistory({ url: cleanUrl, title: data.data.video_title, cover: data.data.image_url });
|
| 711 |
+
document.getElementById('share-container').style.display = 'flex';
|
| 712 |
+
} catch (err) {
|
| 713 |
+
showDebugInfo(`错误:${err.message}`);
|
| 714 |
+
showAlert(`❌ 解析失败:${err.message}`);
|
| 715 |
+
} finally {
|
| 716 |
+
toggleLoading(false);
|
| 717 |
+
isParsing = false;
|
| 718 |
+
}
|
| 719 |
+
}
|
| 720 |
+
|
| 721 |
+
// —— 5. 图集预览:闭包变量 & 批量绑定 ——
|
| 722 |
+
let galleryImages = [];
|
| 723 |
+
let currentIndex = 0;
|
| 724 |
+
|
| 725 |
+
function updateModalImage() {
|
| 726 |
+
document.getElementById('modal-image').src = galleryImages[currentIndex];
|
| 727 |
+
}
|
| 728 |
+
|
| 729 |
+
document.getElementById('image-close').addEventListener('click', () => {
|
| 730 |
+
document.getElementById('image-modal').style.display = 'none';
|
| 731 |
+
});
|
| 732 |
+
document.getElementById('image-prev').addEventListener('click', () => {
|
| 733 |
+
if (currentIndex > 0) {
|
| 734 |
+
currentIndex--;
|
| 735 |
+
updateModalImage();
|
| 736 |
+
}
|
| 737 |
+
});
|
| 738 |
+
document.getElementById('image-next').addEventListener('click', () => {
|
| 739 |
+
if (currentIndex < galleryImages.length - 1) {
|
| 740 |
+
currentIndex++;
|
| 741 |
+
updateModalImage();
|
| 742 |
+
}
|
| 743 |
+
});
|
| 744 |
+
|
| 745 |
+
// —— 6. renderContent 中图集渲染改造示例 ——
|
| 746 |
+
function renderContent(data) {
|
| 747 |
+
const contentBox = document.getElementById('contentBox');
|
| 748 |
+
contentBox.innerHTML = '';
|
| 749 |
+
|
| 750 |
+
if (data.images) {
|
| 751 |
+
// 把 images 赋给闭包
|
| 752 |
+
galleryImages = data.images;
|
| 753 |
+
|
| 754 |
+
// 生成只带 data-index 的缩略图
|
| 755 |
+
const galleryHTML = data.images.map((img, idx) => `
|
| 756 |
+
<div class="gallery-item" data-index="${idx}">
|
| 757 |
+
< img src="${img}" alt="图集 ${idx + 1}"
|
| 758 |
+
loading="lazy"
|
| 759 |
+
style="width:100%;aspect-ratio:1/1;object-fit:cover;cursor:pointer;">
|
| 760 |
+
<div class="image-index">${idx+1}</div>
|
| 761 |
+
</div>
|
| 762 |
+
`).join('');
|
| 763 |
+
|
| 764 |
+
contentBox.innerHTML = `
|
| 765 |
+
<div class="media-card">
|
| 766 |
+
<h2 style="color: var(--primary-color);"><i class="fas fa-images"></i>${data.title||'未命名图集'}</h2>
|
| 767 |
+
<div id="gallery-grid" style="display:grid;gap:10px;grid-template-columns:repeat(auto-fit,minmax(150px,1fr));">
|
| 768 |
+
${galleryHTML}
|
| 769 |
+
</div>
|
| 770 |
+
<div style="text-align:center;margin-top:15px;">
|
| 771 |
+
<i class="fas fa-file-archive"></i> 打包下载
|
| 772 |
+
</div>
|
| 773 |
+
</div>
|
| 774 |
+
`;
|
| 775 |
+
contentBox.style.display = 'block';
|
| 776 |
+
contentBox.scrollIntoView({ behavior: 'smooth' });
|
| 777 |
+
|
| 778 |
+
// 批量绑定点击事件
|
| 779 |
+
document.querySelectorAll('#gallery-grid .gallery-item').forEach(el => {
|
| 780 |
+
el.addEventListener('click', () => {
|
| 781 |
+
currentIndex = parseInt(el.getAttribute('data-index'), 10);
|
| 782 |
+
updateModalImage();
|
| 783 |
+
document.getElementById('image-modal').style.display = 'flex';
|
| 784 |
+
});
|
| 785 |
+
});
|
| 786 |
+
|
| 787 |
|
| 788 |
setInterval(updateTime, 1000);
|
| 789 |
updateTime();
|