// ==UserScript== // @name 畅捷通下载助手QQ1277745546 // @namespace http://tampermonkey.net/ // @version 1.0 // @description Guaranteed panel display version // @author 技术小胥QQ1277745546 // @match https://www.chanjetvip.com/product/goods/detail?id=* // @grant GM_xmlhttpRequest // @grant GM_notification // @grant GM_addStyle // @grant GM_setClipboard // @grant unsafeWindow // @run-at document-end // ==/UserScript== (function() { 'use strict'; // 确保只运行一次 if (window.tplusPanelLoaded) return; window.tplusPanelLoaded = true; // 自定义样式 - 精简版确保兼容性 const css = ` #tplus-download-panel { position: fixed; bottom: 20px; right: 20px; background: white; padding: 10px; border: 1px solid #ddd; border-radius: 5px; box-shadow: 0 2px 10px rgba(0,0,0,0.1); z-index: 999999; width: 350px; font-family: Arial, sans-serif; } .tplus-btn { padding: 5px 10px; margin: 3px; border: none; border-radius: 3px; cursor: pointer; } .tplus-scan-btn { background: #2196F3; color: white; } .tplus-fetch-btn { background: #FF9800; color: white; } .tplus-copy-btn { background: #4CAF50; color: white; } #tplus-link-container { max-height: 300px; overflow-y: auto; margin: 10px 0; border: 1px solid #eee; padding: 5px; } .tplus-status { font-size: 12px; color: #666; margin-top: 5px; } `; const style = document.createElement('style'); style.textContent = css; document.head.appendChild(style); // 创建面板函数 - 增强稳定性 function createPanel() { // 移除可能存在的旧面板 const oldPanel = document.getElementById('tplus-download-panel'); if (oldPanel) oldPanel.remove(); const panel = document.createElement('div'); panel.id = 'tplus-download-panel'; panel.innerHTML = `

畅捷通下载助手

准备就绪
`; // 多种追加方式确保面板显示 const appendMethods = [ () => document.body.appendChild(panel), () => document.documentElement.appendChild(panel), () => { const container = document.createElement('div'); container.id = 'tplus-container'; container.appendChild(panel); document.body.appendChild(container); } ]; for (const method of appendMethods) { try { method(); break; } catch(e) { console.log('Panel append method failed, trying next'); } } // 添加事件监听 document.getElementById('tplus-scan-btn').addEventListener('click', scanLinks); document.getElementById('tplus-fetch-btn').addEventListener('click', fetchLinks); document.getElementById('tplus-copy-btn').addEventListener('click', copyLinks); // 最终检查面板是否存在 setTimeout(() => { if (!document.getElementById('tplus-download-panel')) { console.error('Panel still not found, using last resort'); document.write('
'); document.getElementById('tplus-download-panel').innerHTML = panel.innerHTML; } }, 1000); } // 存储链接数据 let links = []; // 扫描链接 function scanLinks() { updateStatus('正在扫描链接...'); const scanBtn = document.getElementById('tplus-scan-btn'); scanBtn.disabled = true; // 多种选择器尝试 const selectors = [ 'a[href*="/product/goods/download-version"]', 'a[onclick*="download"]', 'a:contains("下载该版本")' ]; let foundLinks = []; for (const selector of selectors) { if (foundLinks.length === 0) { foundLinks = [...document.querySelectorAll(selector)]; } } if (foundLinks.length === 0) { updateStatus('未找到下载链接,请刷新页面重试'); scanBtn.disabled = false; return; } links = foundLinks.map(link => ({ element: link, url: link.href, realUrl: null, status: '待获取' })); displayLinks(); document.getElementById('tplus-fetch-btn').disabled = false; scanBtn.disabled = false; updateStatus(`找到 ${links.length} 个下载链接`); } // 显示链接 function displayLinks() { const container = document.getElementById('tplus-link-container'); container.innerHTML = ''; links.forEach((link, index) => { const linkDiv = document.createElement('div'); linkDiv.style.margin = '5px 0'; linkDiv.style.padding = '5px'; linkDiv.style.borderBottom = '1px dashed #eee'; linkDiv.innerHTML = `
链接 ${index + 1}: ${link.status}
${link.realUrl || link.url}
`; container.appendChild(linkDiv); }); } // 获取真实链接 function fetchLinks() { const fetchBtn = document.getElementById('tplus-fetch-btn'); fetchBtn.disabled = true; updateStatus('开始获取真实链接...'); let completed = 0; links.forEach((link, index) => { setTimeout(() => { GM_xmlhttpRequest({ method: 'GET', url: link.url, headers: { 'X-Requested-With': 'XMLHttpRequest', 'Referer': window.location.href }, onload: function(response) { const finalUrl = response.finalUrl || response.responseURL; if (finalUrl && finalUrl !== link.url) { link.realUrl = finalUrl; link.status = '获取成功'; } else { link.status = '获取失败'; } completed++; displayLinks(); if (completed === links.length) { fetchBtn.disabled = false; document.getElementById('tplus-copy-btn').disabled = false; updateStatus(`完成!成功: ${links.filter(l => l.status === '获取成功').length}/${links.length}`); } }, onerror: function() { link.status = '获取失败'; completed++; displayLinks(); if (completed === links.length) { fetchBtn.disabled = false; document.getElementById('tplus-copy-btn').disabled = false; updateStatus(`完成!成功: ${links.filter(l => l.status === '获取成功').length}/${links.length}`); } } }); }, index * 1500); // 间隔1.5秒 }); } // 复制链接 function copyLinks() { const urls = links.map(link => link.realUrl || link.url).join('\n'); GM_setClipboard(urls); updateStatus('已复制所有链接到剪贴板'); GM_notification({ title: '复制成功', text: '所有链接已复制', timeout: 2000 }); } // 更新状态 function updateStatus(msg) { const statusEl = document.getElementById('tplus-status'); if (statusEl) statusEl.textContent = msg; } // 多重初始化保障 function init() { // 方法1: DOMContentLoaded if (document.readyState !== 'loading') { createPanel(); } else { document.addEventListener('DOMContentLoaded', createPanel); } // 方法2: load事件 window.addEventListener('load', createPanel); // 方法3: 定时检查 let retries = 0; const checkInterval = setInterval(() => { if (document.getElementById('tplus-download-panel') || retries > 5) { clearInterval(checkInterval); } else { createPanel(); retries++; } }, 1000); } // 启动 init(); })();