// ==UserScript== // @name 应用宝网页下载 // @namespace https://viayoo.com/vqu5z0 // @version 1.1 // @description 替换应用宝下载按钮,可以在浏览器下载。 // @author Aloazny // @icon https://sj.qq.com/favicon.ico // @match https://sj.qq.com/* // @match https://a.app.qq.com/o/simple.jsp?pkgname=* // @grant none // @run-at document-end // @license MIT // ==/UserScript== (function() { 'use strict'; const adblockRules = () => { const selectors = ['div[component-id="yybn_game_related_game"]', 'div[dt-eid="brand_banner"]', 'div[component-id="YYB_HOME_WECHAT_GAME_RECOMMEND"]']; selectors.forEach(sel => { document.querySelectorAll(sel).forEach(el => { if (el && el.style) { el.style.display = 'none !important'; el.remove(); } }); }); }; adblockRules(); new MutationObserver(adblockRules).observe(document.body, { childList: true, subtree: true }); const href = location.href; if (!href.includes('/appdetail/') && !href.includes('a.app.qq.com/o/simple.jsp?pkgname=')) { const redirectListBtn = el => { if (!el || el.tagName === 'A') return; const params = el.getAttribute('dt-params'); if (!params) return; const match = params.match(/[?&]pkgname=([^&]+)/); if (!match) return; const pkgname = match[1]; const target = `https://sj.qq.com/appdetail/${pkgname}`; const a = document.createElement('a'); a.href = target; a.textContent = el.textContent?.trim() || '查看详情'; a.className = el.className; a.style.cssText = el.style.cssText; ['dt-eid', 'dt-params'].forEach(attr => { if (el.hasAttribute(attr)) a.setAttribute(attr, el.getAttribute(attr)); }); el.parentNode.replaceChild(a, el); }; const handleList = () => { // const searchContainers = document.querySelectorAll('[class*="SearchBar"], [class*="searchBar"]'); document.querySelectorAll('[dt-eid*="common_download"], [dt-eid*="safe_download"]').forEach(el => { /* for (const container of searchContainers) { if (container.contains(el)) return; } */ redirectListBtn(el); }); }; handleList(); new MutationObserver(handleList).observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['dt-params', 'dt-eid'] }); } if (href.includes('sj.qq.com/appdetail/')) { const pkg = location.pathname.match(/^\/appdetail\/([^/?]+)/)?.[1]; if (!pkg) return; const target = `https://a.app.qq.com/o/simple.jsp?pkgname=${pkg}`; const redirectDetailBtn = el => { if (!el || el.tagName === 'A') return; const a = document.createElement('a'); a.href = target; a.textContent = '浏览器下载'; a.className = el.className; a.style.cssText = el.style.cssText; a.target = '_blank'; ['dt-eid', 'dt-params', 'title'].forEach(attr => { if (el.hasAttribute(attr)) a.setAttribute(attr, el.getAttribute(attr)); }); el.parentNode.replaceChild(a, el); }; const findDetailBtns = () => { const list = []; document.querySelectorAll('[dt-eid*="download"], [dt-eid*="safe_download"]').forEach(el => { const t = (el.textContent || '').trim(); if (t.includes('下载') || t.includes('官方') || t.includes('安卓')) { list.push(el); } }); return list; }; const handleDetail = () => findDetailBtns().forEach(redirectDetailBtn); handleDetail(); new MutationObserver(handleDetail).observe(document.body, { childList: true, subtree: true, characterData: true, attributes: true }); return; } if (href.includes('a.app.qq.com/o/simple.jsp?pkgname=')) { const main = document.querySelector('.main-download-btn'); const sub = document.querySelector('.sub-download-btn'); const nameEl = document.querySelector('.app-vertical-panel .app-detail-bar > span + span[class]'); if (!main || !sub) return; let appsize = nameEl?.textContent?.trim() || ''; main.textContent = `下载 ${appsize}`; main.classList.remove('weaken-display'); main.style.fontWeight = 'bold'; sub.style.display = 'none'; document.getElementById('yyb-safe-text')?.classList.add('hidden'); document.getElementById('normal-safe-text')?.classList.remove('hidden'); main.addEventListener('click', e => { e.preventDefault(); e.stopPropagation(); sub.click(); }, true); if (!nameEl?.textContent?.trim()) { new MutationObserver(() => { const el = document.querySelector('.app-vertical-panel h3'); if (el?.textContent?.trim()) { name = el.textContent.trim(); main.textContent = `浏览器下载 ${name}`; } }).observe(document.body, { childList: true, subtree: true }); } } })();