// ==UserScript== // @name Switch520下载优化 // @namespace http://tampermonkey.net/ // @version 1.9 // @description Switch520快速显示下载地址 // @author 一身惆怅 // @match https://www.gamer520.com/* // @match https://gamer520.com/* // @match https://*.gamers520.com/* // @connect gamer520.com // @connect www.gamer520.com // @connect gamers520.com // @connect 520.gamers520.com // @grant GM_xmlhttpRequest // @grant GM_setValue // @grant GM_getValue // @grant GM_deleteValue // @grant GM_addValueChangeListener // @grant GM_removeValueChangeListener // @grant GM_openInTab // @grant GM_setClipboard // @run-at document-end // @noframes // @license MIT // ==/UserScript== (() => { 'use strict'; const SITE_HOSTS = ['gamer520.com', 'gamers520.com']; const onSite = (host, list = SITE_HOSTS) => list.some((d) => host === d || host.endsWith(`.${d}`)); const IS_SOURCE = onSite(location.hostname, ['gamer520.com']); const IS_TARGET = onSite(location.hostname, ['gamers520.com']); const KEY = { pending: (id) => `g520_pending_${id}`, result: (id) => `g520_result_${id}`, cache: 'g520_cache', }; const HASH_RE = /(?:^#|&)g520=([A-Za-z0-9-]{16,64})(?:&|$)/; const PENDING_TTL = 90e3; const TAB_TIMEOUT = 45e3; const CACHE_TTL = 6 * 3600e3; const CACHE_MAX = 200; const HOP_TIMEOUT = 8000; const PREFETCH = true; const BLOCK_SEL = 'div.bdp-container'; const GO_SEL = 'a[href*="/go?post_id="], a[href*="/go/?post_id="]'; const PLATFORMS = [ { key: 'baidu', name: '百度网盘', en: 'BAIDU PAN', hosts: ['pan.baidu.com'], path: /^\/s\/[\w-]+/, brand: '#4B8DFF', noCode: '无需提取码' }, { key: 'quark', name: '夸克网盘', en: 'QUARK', hosts: ['pan.quark.cn'], path: /^\/s\/[\w-]+/, brand: '#9067F9', noCode: '无需提取码' }, { key: 'xunlei', name: '迅雷云盘', en: 'THUNDER', hosts: ['pan.xunlei.com'], path: /^\/s\/[\w-]+/, brand: '#28B8E8', noCode: '无需提取码' }, { key: 'gofile', name: 'GOFILE 海外盘', en: 'GOFILE · OVERSEAS', hosts: ['gofile.io', 'www.gofile.io'], path: /^\/d\/[\w-]+/, brand: '#2BB98F', optional: true, noCode: '海外直链 · 无需提取码', noCodeShort: '海外直链' }, ]; const toUrl = (u, base = location.href) => { try { return new URL(String(u).trim(), base); } catch { return null; } }; const safeLink = (raw, base) => { const u = toUrl(raw, base); if (!u || u.username || u.password) return null; if (u.protocol === 'http:') u.protocol = 'https:'; if (u.protocol !== 'https:' || (u.port && u.port !== '443')) return null; const host = u.hostname.toLowerCase(); const p = PLATFORMS.find((x) => x.hosts.includes(host) && x.path.test(u.pathname)); return p ? { key: p.key, url: u.href } : null; }; const safeSiteUrl = (raw, base) => { const u = toUrl(String(raw ?? '').replaceAll('&', '&'), base); return u && u.protocol === 'https:' && !u.username && onSite(u.hostname.toLowerCase()) ? u : null; }; const cleanText = (s, max) => String(s ?? '').replace(/[\u0000-\u001f\u007f]/g, '').trim().slice(0, max); const hasAny = (d) => PLATFORMS.some((p) => d?.links?.[p.key]); const sanitize = (raw) => { const links = {}; for (const p of PLATFORMS) { const it = raw?.links?.[p.key]; const ok = it && safeLink(it.url); if (ok?.key === p.key) links[p.key] = { url: ok.url, pwd: cleanText(it.pwd, 32) }; } return { links, unzip: cleanText(raw?.unzip, 64) }; }; const extractLinks = (doc) => { const scope = doc.querySelector('.bdp-container, .bdp-grid') ?? doc; const links = {}; const take = (raw) => { const hit = raw && safeLink(raw, doc.baseURI || location.href); if (hit && !links[hit.key]) links[hit.key] = { url: hit.url, pwd: '' }; }; for (const img of scope.querySelectorAll('img')) { const src = img.getAttribute('src') || img.getAttribute('data-src') || ''; take(toUrl(src)?.searchParams.get('data')); } for (const a of scope.querySelectorAll('a[href]')) take(a.getAttribute('href')); for (const p of PLATFORMS) { const it = links[p.key]; if (!it) continue; it.pwd = toUrl(it.url)?.searchParams.get('pwd') ?? scope.querySelector(`.bdp-${p.key} .bdp-pwd-box strong`)?.textContent ?? ''; } const head = scope.querySelector('.bdp-header') ?? doc.querySelector('.bdp-header'); const unzip = head?.textContent.match(/解压密码\s*[::]\s*([^\s||]+)/)?.[1] ?? ''; return sanitize({ links, unzip }); }; const JS_JUMPS = [ /location\.(?:replace|assign)\(\s*['"]([^'"]+)['"]/i, /(?:window\.|document\.|top\.|self\.)?location(?:\.href)?\s*=\s*['"]([^'"]+)['"]/i, /window\.open\(\s*['"]([^'"]+)['"]/i, ]; const findNext = (text, doc, base, allowAnchor = true) => { const refresh = doc.querySelector('meta[http-equiv="refresh" i]')?.getAttribute('content')?.match(/url\s*=\s*['"]?([^'"]+)/i); if (refresh) return safeSiteUrl(refresh[1], base)?.href ?? null; for (const re of JS_JUMPS) { const m = text.match(re); const u = m && safeSiteUrl(m[1], base); if (u) return u.href; } if (!allowAnchor) return null; const a = doc.querySelector('a[href*="gamers520.com/"], a[href*="/go?"], a#go, a.go-link'); return a ? safeSiteUrl(a.getAttribute('href'), base)?.href ?? null : null; }; const withToken = (url, id) => { const u = new URL(url); u.hash = `g520=${id}`; return u.href; }; const tokenMatch = location.hash.match(HASH_RE); if (tokenMatch) { const id = tokenMatch[1]; const pending = GM_getValue(KEY.pending(id), null); if (!pending || Date.now() - pending.ts > PENDING_TTL) return; const relay = (allowAnchor) => { const next = findNext(document.documentElement.outerHTML, document, location.href, allowAnchor); if (!next || next.split('#')[0] === location.href.split('#')[0]) return false; location.replace(withToken(next, id)); return true; }; if (IS_SOURCE) { relay(true); return; } if (!IS_TARGET) return; const attempt = (left) => { const data = extractLinks(document); if (!hasAny(data)) { if (left > 0) return setTimeout(attempt, 500, left - 1); if (relay(false)) return; } GM_setValue(KEY.result(id), { ts: Date.now(), data, page: location.href.split('#')[0] }); GM_deleteValue(KEY.pending(id)); setTimeout(() => window.close(), 300); }; attempt(10); return; } if (!IS_SOURCE) return; const gmGet = (url) => new Promise((resolve, reject) => GM_xmlhttpRequest({ method: 'GET', url, timeout: HOP_TIMEOUT, headers: { Referer: location.href }, onload: (r) => resolve({ text: r.responseText ?? '', finalUrl: r.finalUrl || url }), onerror: () => reject(new Error('网络错误')), ontimeout: () => reject(new Error('请求超时')), })); const parser = new DOMParser(); const resolveByRequest = async (url) => { for (let hop = 0, cur = url; hop < 6; hop++) { const { text, finalUrl } = await gmGet(cur); if (!safeSiteUrl(finalUrl)) throw new Error('跳转到了站外地址,已停止'); if (text.length < 12000 && /Just a moment|cf-mitigated|challenge-platform/i.test(text)) { throw new Error('Cloudflare 验证拦截'); } const doc = parser.parseFromString(text, 'text/html'); const data = extractLinks(doc); if (hasAny(data)) return { data, page: finalUrl }; const next = findNext(text, doc, finalUrl); if (!next || next === cur) break; cur = next; } throw new Error('未在跳转链中找到网盘链接'); }; const newId = () => crypto.randomUUID?.() ?? Array.from(crypto.getRandomValues(new Uint8Array(16)), (b) => b.toString(16).padStart(2, '0')).join(''); const liveTabs = new Set(); addEventListener('pagehide', () => { for (const id of liveTabs) { GM_deleteValue(KEY.pending(id)); GM_deleteValue(KEY.result(id)); } }); const resolveByTab = (url) => { const id = newId(); const { promise, resolve, reject } = Promise.withResolvers(); liveTabs.add(id); GM_setValue(KEY.pending(id), { ts: Date.now() }); const tab = GM_openInTab(withToken(url, id), { active: false, insert: true, setParent: true }); const finish = () => { clearTimeout(timer); GM_removeValueChangeListener(listener); GM_deleteValue(KEY.pending(id)); GM_deleteValue(KEY.result(id)); liveTabs.delete(id); try { tab?.close?.(); } catch { } }; const listener = GM_addValueChangeListener(KEY.result(id), (_k, _o, val) => { if (!val) return; finish(); const data = sanitize(val.data); const page = safeSiteUrl(val.page)?.href ?? url; hasAny(data) ? resolve({ data, page }) : reject(new Error('目标页未找到网盘链接')); }); const timer = setTimeout(() => { finish(); reject(new Error('后台标签页超时')); }, TAB_TIMEOUT); return promise; }; const resolveLinks = async ({ goUrl }, allowTab) => { try { return await resolveByRequest(goUrl); } catch (e) { if (!allowTab) throw e; console.warn('[G520] 直连失败,切换后台标签页:', e.message); setStatus('直连受限,正在通过后台标签页解析'); return resolveByTab(goUrl); } }; const loadCache = () => { const c = GM_getValue(KEY.cache, null); return c && typeof c === 'object' && c.items ? c : { v: 2, items: {} }; }; const readCache = (id) => { const e = loadCache().items[id]; if (!e || Date.now() - e.ts >= CACHE_TTL) return null; const data = sanitize(e.data); return hasAny(data) ? { ts: e.ts, data, page: safeSiteUrl(e.page)?.href ?? '' } : null; }; const writeCache = (id, entry) => { const c = loadCache(), now = Date.now(); c.items[id] = entry; let ids = Object.keys(c.items).filter((k) => now - (c.items[k]?.ts ?? 0) < CACHE_TTL); if (ids.length > CACHE_MAX) ids = ids.sort((a, b) => c.items[b].ts - c.items[a].ts).slice(0, CACHE_MAX); GM_setValue(KEY.cache, { v: 2, items: Object.fromEntries(ids.map((k) => [k, c.items[k]])) }); }; const dropLegacy = (id) => { GM_deleteValue(`g520_cache_${id}`); GM_deleteValue(`g520_result_${id}`); }; GM_deleteValue('g520_pending'); const inflight = new Map(); let sideNotify = () => { }; const fetchLinks = (ctx, allowTab) => { const running = inflight.get(ctx.id); if (running) { return !allowTab || running.allowTab ? running.promise : running.promise.catch(() => fetchLinks(ctx, true)); } const promise = resolveLinks(ctx, allowTab) .then(({ data, page }) => { const entry = { ts: Date.now(), data, page }; writeCache(ctx.id, entry); sideNotify(ctx.id, entry); return entry; }) .finally(() => inflight.delete(ctx.id)); inflight.set(ctx.id, { promise, allowTab }); return promise; }; const QR = (() => { const ECC = [0, 10, 16, 26, 18, 24, 16, 18, 22, 22, 26, 30, 22, 22, 24, 24, 28, 28, 26, 26, 26, 26, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28, 28]; const BLOCKS = [0, 1, 1, 1, 2, 2, 4, 4, 4, 5, 5, 5, 8, 9, 9, 10, 10, 11, 13, 14, 16, 17, 17, 18, 20, 21, 23, 25, 26, 28, 29, 31, 33, 35, 37, 38, 40, 43, 45, 47, 49]; const gfMul = (x, y) => { let z = 0; for (let i = 7; i >= 0; i--) { z = (z << 1) ^ ((z >>> 7) * 0x11d); z ^= ((y >>> i) & 1) * x; } return z; }; const rsDivisor = (deg) => { const r = new Array(deg).fill(0); r[deg - 1] = 1; let root = 1; for (let i = 0; i < deg; i++) { for (let j = 0; j < deg; j++) { r[j] = gfMul(r[j], root); if (j + 1 < deg) r[j] ^= r[j + 1]; } root = gfMul(root, 2); } return r; }; const rsRemainder = (data, div) => { const r = div.map(() => 0); for (const b of data) { const f = b ^ r.shift(); r.push(0); div.forEach((c, i) => { r[i] ^= gfMul(c, f); }); } return r; }; const rawModules = (v) => { let r = (16 * v + 128) * v + 64; if (v >= 2) { const n = Math.floor(v / 7) + 2; r -= (25 * n - 10) * n - 55; if (v >= 7) r -= 36; } return r; }; const dataCodewords = (v) => Math.floor(rawModules(v) / 8) - ECC[v] * BLOCKS[v]; const alignPos = (v) => { if (v === 1) return []; const n = Math.floor(v / 7) + 2; const step = v === 32 ? 26 : Math.ceil((v * 4 + 4) / (n * 2 - 2)) * 2; const res = [6]; for (let p = v * 4 + 10; res.length < n; p -= step) res.splice(1, 0, p); return res; }; const MASKS = [ (x, y) => (x + y) % 2 === 0, (x, y) => y % 2 === 0, (x) => x % 3 === 0, (x, y) => (x + y) % 3 === 0, (x, y) => (Math.floor(x / 3) + Math.floor(y / 2)) % 2 === 0, (x, y) => (x * y) % 2 + (x * y) % 3 === 0, (x, y) => ((x * y) % 2 + (x * y) % 3) % 2 === 0, (x, y) => ((x + y) % 2 + (x * y) % 3) % 2 === 0, ]; const penalty = (m, n) => { let p = 0, dark = 0; const line = (get) => { for (let i = 0; i < n; i++) { let run = 1, s = ''; for (let j = 0; j < n; j++) { const c = get(i, j); s += c ? '1' : '0'; if (j > 0 && c === get(i, j - 1)) { run++; if (run === 5) p += 3; else if (run > 5) p++; } else run = 1; } s = `0000${s}0000`; for (let k = s.indexOf('1011101'); k !== -1; k = s.indexOf('1011101', k + 1)) { if (s.slice(k - 4, k) === '0000' || s.slice(k + 7, k + 11) === '0000') p += 40; } } }; line((y, x) => m[y][x]); line((x, y) => m[y][x]); for (let y = 0; y < n; y++) { for (let x = 0; x < n; x++) { if (m[y][x]) dark++; if (x < n - 1 && y < n - 1) { const c = m[y][x]; if (c === m[y][x + 1] && c === m[y + 1][x] && c === m[y + 1][x + 1]) p += 3; } } } const total = n * n; return p + (Math.ceil(Math.abs(dark * 20 - total * 10) / total) - 1) * 10; }; const encode = (text) => { const bytes = [...new TextEncoder().encode(text)]; let ver = 1; for (; ver <= 40; ver++) { if (4 + (ver < 10 ? 8 : 16) + bytes.length * 8 <= dataCodewords(ver) * 8) break; } if (ver > 40) throw new Error('链接过长,无法生成二维码'); const bits = []; const put = (val, len) => { for (let i = len - 1; i >= 0; i--) bits.push((val >>> i) & 1); }; const cap = dataCodewords(ver) * 8; put(4, 4); put(bytes.length, ver < 10 ? 8 : 16); for (const b of bytes) put(b, 8); put(0, Math.min(4, cap - bits.length)); put(0, (8 - (bits.length % 8)) % 8); for (let pad = 0xec; bits.length < cap; pad ^= 0xec ^ 0x11) put(pad, 8); const data = []; for (let i = 0; i < bits.length; i += 8) data.push(bits.slice(i, i + 8).reduce((a, b) => (a << 1) | b, 0)); const nBlocks = BLOCKS[ver], eccLen = ECC[ver], raw = Math.floor(rawModules(ver) / 8); const nShort = nBlocks - (raw % nBlocks), shortLen = Math.floor(raw / nBlocks); const div = rsDivisor(eccLen), blocks = []; for (let i = 0, k = 0; i < nBlocks; i++) { const dat = data.slice(k, k + shortLen - eccLen + (i < nShort ? 0 : 1)); k += dat.length; const ecc = rsRemainder(dat, div); if (i < nShort) dat.push(0); blocks.push(dat.concat(ecc)); } const words = []; for (let i = 0; i < blocks[0].length; i++) { blocks.forEach((b, j) => { if (i !== shortLen - eccLen || j >= nShort) words.push(b[i]); }); } const n = ver * 4 + 17; const mod = Array.from({ length: n }, () => new Array(n).fill(false)); const fn = Array.from({ length: n }, () => new Array(n).fill(false)); const setF = (x, y, dark) => { mod[y][x] = dark; fn[y][x] = true; }; for (let i = 0; i < n; i++) { setF(6, i, i % 2 === 0); setF(i, 6, i % 2 === 0); } for (const [cx, cy] of [[3, 3], [n - 4, 3], [3, n - 4]]) { for (let dy = -4; dy <= 4; dy++) { for (let dx = -4; dx <= 4; dx++) { const x = cx + dx, y = cy + dy, d = Math.max(Math.abs(dx), Math.abs(dy)); if (x >= 0 && x < n && y >= 0 && y < n) setF(x, y, d !== 2 && d !== 4); } } } const al = alignPos(ver), last = al.length - 1; al.forEach((ax, i) => al.forEach((ay, j) => { if ((i === 0 && j === 0) || (i === 0 && j === last) || (i === last && j === 0)) return; for (let dy = -2; dy <= 2; dy++) { for (let dx = -2; dx <= 2; dx++) setF(ax + dx, ay + dy, Math.max(Math.abs(dx), Math.abs(dy)) !== 1); } })); const drawFormat = (mask) => { const d = mask; let rem = d; for (let i = 0; i < 10; i++) rem = (rem << 1) ^ ((rem >>> 9) * 0x537); const f = ((d << 10) | rem) ^ 0x5412; const bit = (i) => ((f >>> i) & 1) === 1; for (let i = 0; i <= 5; i++) setF(8, i, bit(i)); setF(8, 7, bit(6)); setF(8, 8, bit(7)); setF(7, 8, bit(8)); for (let i = 9; i < 15; i++) setF(14 - i, 8, bit(i)); for (let i = 0; i < 8; i++) setF(n - 1 - i, 8, bit(i)); for (let i = 8; i < 15; i++) setF(8, n - 15 + i, bit(i)); setF(8, n - 8, true); }; drawFormat(0); if (ver >= 7) { let rem = ver; for (let i = 0; i < 12; i++) rem = (rem << 1) ^ ((rem >>> 11) * 0x1f25); const v = (ver << 12) | rem; for (let i = 0; i < 18; i++) { const c = ((v >>> i) & 1) === 1, a = n - 11 + (i % 3), b = Math.floor(i / 3); setF(a, b, c); setF(b, a, c); } } let idx = 0; for (let right = n - 1; right >= 1; right -= 2) { if (right === 6) right = 5; for (let vert = 0; vert < n; vert++) { for (let j = 0; j < 2; j++) { const x = right - j, up = ((right + 1) & 2) === 0, y = up ? n - 1 - vert : vert; if (!fn[y][x] && idx < words.length * 8) { mod[y][x] = ((words[idx >>> 3] >>> (7 - (idx & 7))) & 1) === 1; idx++; } } } } const applyMask = (m) => { for (let y = 0; y < n; y++) for (let x = 0; x < n; x++) if (!fn[y][x] && MASKS[m](x, y)) mod[y][x] = !mod[y][x]; }; let best = 0, bestP = Infinity; for (let m = 0; m < 8; m++) { applyMask(m); drawFormat(m); const p = penalty(mod, n); if (p < bestP) { bestP = p; best = m; } applyMask(m); } applyMask(best); drawFormat(best); return mod; }; const cache = new Map(); const svg = (text, quiet = 2) => { if (!cache.has(text)) { const m = encode(text), n = m.length + quiet * 2; let d = ''; m.forEach((row, y) => { for (let x = 0; x < row.length; x++) { if (!row[x]) continue; let w = 1; while (row[x + w]) w++; d += `M${x + quiet} ${y + quiet}h${w}v1h-${w}z`; x += w - 1; } }); cache.set(text, ``); } return cache.get(text); }; return { encode, svg }; })(); const ICON = { close: '', qr: '', link: '', copy: '', open: '', refresh: '', stack: '', check: '', alert: '', }; const CSS = ` :host{all:initial} *,*::before,*::after{box-sizing:border-box} .ld{ --bg:#0B0D12;--surface:#11151D;--card:#10141C;--sunken:#0A0D12; --text:#E8EDF5;--text-2:#929BAA;--text-3:#687386; --line:rgba(255,255,255,.08);--line-2:rgba(255,255,255,.12); --accent:#4B8DFF;--r-lg:14px;--r-md:10px;--r-sm:8px; --sans:-apple-system,BlinkMacSystemFont,"Segoe UI","PingFang SC","Hiragino Sans GB","Microsoft YaHei",system-ui,sans-serif; --mono:ui-monospace,SFMono-Regular,"Cascadia Mono",Consolas,Menlo,monospace; font-family:var(--sans);font-size:14px;line-height:1.5;color:var(--text); -webkit-font-smoothing:antialiased; } button{font:inherit;color:inherit;background:none;border:0;margin:0;padding:0;cursor:pointer} a{color:inherit;text-decoration:none} svg{display:block;flex:none} :focus-visible{outline:2px solid rgba(75,141,255,.7);outline-offset:2px} .ld-mask{position:fixed;inset:0;z-index:2147483000;display:flex;align-items:center;justify-content:center;padding:16px; background:rgba(4,5,8,.72);backdrop-filter:blur(2px);opacity:0;transition:opacity .18s ease} .ld-mask.show{opacity:1} .ld-panel{position:relative;display:flex;flex-direction:column;width:min(920px,100%);max-height:calc(100vh - 32px); background:var(--bg);border:1px solid var(--line);border-radius:var(--r-lg); box-shadow:0 1px 0 rgba(255,255,255,.04) inset,0 24px 64px -12px rgba(0,0,0,.7),0 8px 24px rgba(0,0,0,.35); transform:translateY(8px);transition:transform .18s ease} .ld-mask.show .ld-panel{transform:none} .ld-head{display:flex;align-items:center;justify-content:space-between;gap:16px;padding:18px 24px 0} .ld-title{font-size:16px;font-weight:600;letter-spacing:.02em;color:var(--text)} .ld-close{display:grid;place-items:center;width:32px;height:32px;border-radius:var(--r-sm);color:var(--text-2); border:1px solid transparent;transition:background .15s,color .15s,border-color .15s} .ld-close:hover{background:var(--surface);border-color:var(--line);color:var(--text)} .ld-close:active{background:var(--sunken)} .ld-game{margin:14px 24px 0;padding-bottom:18px;border-bottom:1px solid var(--line);font-size:16px;font-weight:600;line-height:1.45;color:var(--text); display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;overflow:hidden;word-break:break-word} .ld-body{flex:1 1 auto;min-height:0;overflow:auto;padding:20px 24px} .ld-meta{display:grid;grid-template-columns:repeat(auto-fit,minmax(200px,1fr));gap:12px;margin-bottom:20px} .ld-secret{display:flex;align-items:center;justify-content:space-between;gap:12px;width:100%;padding:12px 14px;text-align:left; background:var(--surface);border:1px solid var(--line);border-radius:var(--r-md);transition:border-color .15s,background .15s} .ld-secret:hover{border-color:var(--line-2);background:#141922} .ld-secret:active{background:var(--sunken)} .ld-secret-k{display:block;font-size:12px;color:var(--text-3)} .ld-secret-v{display:block;margin-top:2px;font-family:var(--mono);font-size:15px;letter-spacing:.04em;color:var(--text);word-break:break-all} .ld-secret-i{color:var(--text-3);transition:color .15s} .ld-secret:hover .ld-secret-i{color:var(--text-2)} .ld-grid{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:12px} .ld-grid[data-n="1"]{grid-template-columns:minmax(0,1fr)} .ld-grid[data-n="2"],.ld-grid[data-n="4"]{grid-template-columns:repeat(2,minmax(0,1fr))} .ld-grid[data-n="1"] .ld-url{min-height:0} .ld-grid[data-n="1"] .ld-btns{width:min(420px,100%);margin-left:auto} .ld-miss{margin:12px 2px 0;font-size:12px;color:var(--text-3)} @media (max-width:880px){.ld-grid:not([data-n="1"]){grid-template-columns:repeat(2,minmax(0,1fr))}} @media (max-width:600px){.ld-grid:not([data-n="1"]){grid-template-columns:minmax(0,1fr)}.ld-grid[data-n="1"] .ld-btns{width:100%}.ld-head,.ld-body{padding-left:16px;padding-right:16px}.ld-game{margin-left:16px;margin-right:16px}.ld-foot{padding-left:16px;padding-right:16px}} .ld-card{--brand:#4B8DFF;display:flex;flex-direction:column;gap:12px;min-width:0;padding:16px; background:var(--card);border:1px solid var(--line);border-radius:var(--r-md);transition:border-color .15s} .ld-card:hover{border-color:var(--line-2)} .ld-card-top{display:flex;align-items:center;gap:10px;min-width:0} .ld-ico{display:grid;place-items:center;width:36px;height:36px;flex:none;border-radius:var(--r-sm);background:var(--sunken);border:1px solid var(--line)} .ld-ico svg{width:24px;height:24px} .ld-name{min-width:0;flex:1} .ld-name b{display:block;font-size:14px;font-weight:600;color:var(--text)} .ld-name small{display:block;font-size:11px;letter-spacing:.08em;color:var(--text-3)} .ld-qrbtn{display:inline-flex;align-items:center;gap:6px;height:28px;padding:0 10px;border-radius:var(--r-sm);font-size:12px;color:var(--text-2); border:1px solid var(--line);background:var(--sunken);transition:color .15s,border-color .15s} .ld-qrbtn:hover,.ld-qrbtn[aria-expanded="true"]{color:var(--text);border-color:var(--line-2)} .ld-url{display:flex;gap:8px;align-items:flex-start;padding:10px 12px;min-height:62px;background:var(--sunken);border:1px solid var(--line);border-radius:var(--r-sm); font-family:var(--mono);font-size:12px;line-height:1.55;color:#C7CEDA;overflow-wrap:anywhere;word-break:break-all} .ld-url svg{margin-top:3px;color:var(--text-3)} .ld-url span{min-width:0} .ld-code{display:flex;align-items:center;gap:8px;height:24px;font-size:12px;color:var(--text-3)} .ld-code b{display:inline-flex;align-items:center;height:24px;padding:0 8px;border-radius:6px;font-family:var(--mono);font-size:13px;font-weight:600;letter-spacing:.08em; color:var(--text);background:color-mix(in srgb,var(--brand) 12%,transparent);border:1px solid color-mix(in srgb,var(--brand) 26%,transparent)} .ld-code i{font-style:normal;color:var(--text-3)} .ld-btns{display:grid;grid-template-columns:1.4fr 1fr;gap:8px;margin-top:auto} .ld-btn{display:inline-flex;align-items:center;justify-content:center;gap:6px;height:36px;border-radius:var(--r-sm);font-size:13px;font-weight:600; transition:filter .15s,background .15s,border-color .15s,transform .12s} .ld-btn:active{transform:translateY(1px)} .ld-btn.primary{color:#fff;background:color-mix(in srgb,var(--brand) 82%,#0B0D12);border:1px solid color-mix(in srgb,var(--brand) 90%,#fff 10%)} .ld-btn.primary:hover{filter:brightness(1.1)} .ld-btn.secondary{color:var(--text);background:var(--surface);border:1px solid var(--line-2)} .ld-btn.secondary:hover{background:#171C26;border-color:rgba(255,255,255,.18)} .ld-btn[disabled],.ld-btn[aria-disabled="true"]{opacity:.4;pointer-events:none} .ld-foot{display:flex;align-items:center;justify-content:space-between;flex-wrap:wrap;gap:8px 16px;padding:12px 24px 16px;border-top:1px solid var(--line);font-size:12px;color:var(--text-3)} .ld-actions{display:flex;flex-wrap:wrap;gap:4px} .ld-act{display:inline-flex;align-items:center;gap:6px;height:30px;padding:0 10px;border-radius:var(--r-sm);color:var(--text-2);transition:background .15s,color .15s} .ld-act:hover{background:var(--surface);color:var(--text)} .ld-act:active{background:var(--sunken)} .ld-state{display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;min-height:240px;text-align:center;color:var(--text-2)} .ld-spin{width:22px;height:22px;border-radius:50%;border:2px solid var(--line-2);border-top-color:var(--accent);animation:ld-spin .8s linear infinite} @keyframes ld-spin{to{transform:rotate(360deg)}} .ld-state.err{color:#E58A9B} .ld-state.err p{margin:0;max-width:420px;color:var(--text-2)} .ld-state .ld-btns{width:min(320px,100%);margin-top:4px} .ld-pop{position:fixed;z-index:2147483646;padding:12px 12px 10px;background:var(--surface);border:1px solid var(--line-2);border-radius:var(--r-md); box-shadow:0 16px 40px rgba(0,0,0,.55);opacity:0;transform:translateY(4px);pointer-events:none;transition:opacity .15s,transform .15s;text-align:center} .ld-pop.show{opacity:1;transform:none} .ld-pop-img{display:grid;place-items:center;width:176px;height:176px;padding:10px;background:#fff;border-radius:var(--r-sm)} .ld-pop-img svg{display:block;width:156px;height:156px} .ld-pop-err{font-size:12px;color:var(--text-3)} .ld-pop-cap{margin-top:8px;font-size:12px;color:var(--text-2)} .ld-toast{position:fixed;left:50%;bottom:40px;z-index:2147483647;display:inline-flex;align-items:center;gap:8px;padding:9px 14px;border-radius:var(--r-sm); font-size:13px;color:var(--text);background:#151A23;border:1px solid var(--line-2);box-shadow:0 10px 30px rgba(0,0,0,.45); transform:translate(-50%,6px);opacity:0;transition:opacity .15s,transform .15s;pointer-events:none} .ld-toast svg{color:#5FD08A} .ld-toast.show{opacity:1;transform:translate(-50%,0)} .ld[data-tone]{--s-text:#E8EDF5;--s-2:#A3ACBA;--s-3:#78818F;--s-chip:rgba(255,255,255,.045);--s-line:rgba(255,255,255,.09);--s-btn:rgba(255,255,255,.06);--s-btn-h:rgba(255,255,255,.1)} .ld[data-tone="light"]{--s-text:#1F2329;--s-2:#4B5260;--s-3:#8A919E;--s-chip:#F5F7FA;--s-line:rgba(15,23,42,.09);--s-btn:#F1F3F6;--s-btn-h:#E7EAEF} .ld-side{display:flex;flex-direction:column;gap:10px;color:var(--s-text);font-size:13px} .ld-side-head{display:flex;align-items:center;justify-content:space-between;gap:8px;margin-bottom:2px} .ld-side-title{margin:0;font-size:15px;font-weight:600;line-height:1;letter-spacing:.5px;color:var(--s-text)} .ld-side-age{font-size:11px;color:var(--s-3)} .ld-side-hint{font-size:12px;color:var(--s-2)} .ld-side-pwd{display:flex;align-items:center;justify-content:space-between;gap:8px;width:100%;padding:8px 10px;border-radius:6px;font-size:12px;color:var(--s-2); background:var(--s-chip);border:1px dashed var(--s-line);text-align:left;transition:border-color .15s} .ld-side-pwd b{font-family:var(--mono);font-size:13px;font-weight:600;letter-spacing:.04em;color:var(--s-text);word-break:break-all;text-align:right} .ld-side-pwd:hover{border-style:solid;border-color:var(--s-3)} .ld-rows{display:flex;flex-direction:column;gap:8px} .ld-row{display:flex;flex-direction:column;gap:8px;padding:10px;border-radius:8px;background:var(--s-chip);border:1px solid var(--s-line);box-shadow:inset 3px 0 0 var(--brand,transparent)} .ld-row.sk{gap:10px} .ld-row-top{display:flex;align-items:center;gap:8px;min-width:0} .ld-row-ico{display:grid;place-items:center;width:20px;height:20px;flex:none} .ld-row-ico svg{width:18px;height:18px} .ld-row-name{flex:1;min-width:0;font-size:13px;font-weight:600;white-space:nowrap;overflow:hidden;text-overflow:ellipsis} .ld-row-pwd{display:inline-flex;align-items:center;gap:5px;height:22px;padding:0 7px;border-radius:5px;font-family:var(--mono);font-size:12px;font-weight:600;letter-spacing:.06em;color:var(--s-text); background:color-mix(in srgb,var(--brand) 14%,transparent);border:1px solid color-mix(in srgb,var(--brand) 32%,transparent)} .ld-row-pwd i{font-style:normal;font-family:var(--sans);font-weight:400;letter-spacing:0;font-size:11px;color:var(--s-2)} .ld-row-nopwd{font-size:11px;color:var(--s-3);white-space:nowrap} .ld-row-btns{display:grid;grid-template-columns:1fr 1fr 32px;gap:6px} .ld-sbtn{display:inline-flex;align-items:center;justify-content:center;gap:5px;height:30px;padding:0 8px;border-radius:6px;font-size:12px;font-weight:600;white-space:nowrap; color:var(--s-text);background:var(--s-btn);border:1px solid var(--s-line);transition:background .15s,filter .15s,transform .12s} .ld-sbtn:hover,.ld-sbtn[aria-expanded="true"]{background:var(--s-btn-h)} .ld-sbtn:active{transform:translateY(1px)} .ld-sbtn svg{width:13px;height:13px} .ld-sbtn.ico{padding:0} .ld-sbtn.primary{color:#fff;background:color-mix(in srgb,var(--brand,#3A7BEF) 85%,#000);border-color:color-mix(in srgb,var(--brand,#3A7BEF) 90%,#fff 10%)} .ld-sbtn.primary:hover{filter:brightness(1.1);background:color-mix(in srgb,var(--brand,#3A7BEF) 85%,#000)} .ld-side-miss{font-size:12px;color:var(--s-3)} .ld-side-acts{display:grid;grid-template-columns:1fr 1fr;gap:6px} .ld-side-acts.one{grid-template-columns:1fr} .ld-side-err{display:flex;align-items:flex-start;gap:8px;padding:10px;border-radius:8px;font-size:12px;line-height:1.5;color:var(--s-2);background:var(--s-chip);border:1px solid var(--s-line)} .ld-side-err svg{width:16px;height:16px;flex:none;color:#E58A9B;margin-top:1px} .ld[data-tone="light"] .ld-sk{background:linear-gradient(90deg,#eef0f3 0%,#e3e6ea 50%,#eef0f3 100%);background-size:200% 100%} .ld-hint{margin:0 0 12px;font-size:12px;color:var(--text-2)} .ld-hint:empty{display:none} .ld-sk{display:block;height:10px;border-radius:4px;background:linear-gradient(90deg,#151a23 0%,#1b212c 50%,#151a23 100%);background-size:200% 100%;animation:ld-shimmer 1.4s ease-in-out infinite} @keyframes ld-shimmer{from{background-position:100% 0}to{background-position:-100% 0}} .ld-card.sk .ld-url{flex-direction:column;gap:8px;justify-content:center} .ld-card.sk .ld-btn{pointer-events:none;opacity:.35} @media (prefers-reduced-motion:reduce){*,*::before,*::after{transition:none!important;animation-duration:1.5s!important}} `; const LOGO = { baidu: '', quark: '', xunlei: '', gofile: '', }; const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => `${c.charCodeAt(0)};`); const el = (className, attrs = {}) => { const node = document.createElement('div'); node.className = className; for (const [k, v] of Object.entries(attrs)) node.setAttribute(k, v); return node; }; let SHEET = null; try { if ('adoptedStyleSheets' in Document.prototype) { SHEET = new CSSStyleSheet(); SHEET.replaceSync(CSS); } } catch { SHEET = null; } const makeHost = (id) => { const host = document.createElement('div'); host.id = id; const root = host.attachShadow({ mode: 'open' }); let adopted = false; if (SHEET) { try { root.adoptedStyleSheets = [SHEET]; adopted = true; } catch { } } if (!adopted) { const style = document.createElement('style'); style.textContent = CSS; root.append(style); } const wrap = el('ld'); root.append(wrap); return { host, wrap }; }; const UI = makeHost('loot-drop-root'); document.documentElement.append(UI.host); let toastEl, toastTimer; const toast = (msg) => { toastEl ??= UI.wrap.appendChild(el('ld-toast', { role: 'status' })); toastEl.innerHTML = `${ICON.check}${esc(msg)}`; toastEl.classList.add('show'); clearTimeout(toastTimer); toastTimer = setTimeout(() => toastEl.classList.remove('show'), 1600); }; const copy = (text, label) => { try { GM_setClipboard(text, 'text'); } catch { navigator.clipboard?.writeText(text); } toast(label ? `已复制 · ${label}` : '已复制'); }; let mask = null, body = null, lastFocus = null, view = null, runToken = 0; let pop = null, popOwner = null; const setStatus = (text) => { const hint = mask?.querySelector('.ld-hint'); if (hint) hint.textContent = text; }; const dropFoot = () => mask?.querySelector('.ld-foot')?.remove(); const placePop = (btn) => { const { top, right, bottom } = btn.getBoundingClientRect(); const w = 202, h = 230, gap = 8; pop.style.left = `${Math.min(Math.max(8, right - w), innerWidth - w - 8)}px`; pop.style.top = `${top - h - gap < 8 ? bottom + gap : top - h - gap}px`; }; const hideQr = () => { popOwner?.setAttribute('aria-expanded', 'false'); popOwner = null; pop?.classList.remove('show'); }; const qrData = (btn) => (btn.closest('.ld-side') ? side.data : view?.data); const showQr = (btn) => { const p = PLATFORMS.find((x) => x.key === btn.dataset.qr); const item = p && qrData(btn)?.links?.[p.key]; if (!item) return; pop ??= UI.wrap.appendChild(el('ld-pop', { role: 'tooltip' })); popOwner?.setAttribute('aria-expanded', 'false'); popOwner = btn; btn.setAttribute('aria-expanded', 'true'); let qr; try { qr = QR.svg(item.url); } catch (e) { qr = `${esc(e.message)}`; } pop.innerHTML = `
解析失败:${esc(err.message ?? err)}