// ==UserScript== // @name 百度文库下载器,VIP文档免VIP下载 | 全文阅读| 开启右键复制 // @version 1.7.7 // @description 【本脚本功能】保持源文件排版导出 PDF 文件,解除继续阅读限制,净化弹窗、广告,开启文库本地 VIP,淘宝、天猫、京东商品优惠券查询 // @author zhihu // @antifeature membership 为防止接口被盗!该脚本需要输入验证码之后才能使用完整功能,感谢理解 // @license End-User License Agreement // @match *://wenku.baidu.com/view* // @match *://wk.baidu.com/view* // @match *://wenku.baidu.com/tfview* // @match *://wk.baidu.com/tfview* // @icon https://www.baidu.com/favicon.ico // @grant GM_getValue // @grant GM.getValue // @grant GM_setValue // @grant GM.setValue // @connect wenku.baidu.com // @connect bdimg.com // @connect tool.wezhicms.com // @connect zhihuweb.com // @grant unsafeWindow // @grant GM.xmlHttpRequest // @grant GM_xmlhttpRequest // @run-at document-start // @namespace http://zhihupe.com/ // @downloadURL none // ==/UserScript== (function () { 'use strict'; function getvip() { // 注册个 MutationObserver,根治各种垃圾弹窗 let count = 0; const blackListSelector = [ '.vip-pay-pop-v2-wrap', '.reader-pop-manager-view-containter', '.fc-ad-contain', '.shops-hot', '.video-rec-wrap', '.pay-doc-marquee', '.card-vip', '.vip-privilege-card-wrap', '.doc-price-voucher-wrap', '.vip-activity-wrap-new', '.creader-root .hx-warp', '.hx-recom-wrapper', '.hx-bottom-wrapper', '.hx-right-wrapper.sider-edge' ] const killTarget = (item) => { if (item.nodeType !== Node.ELEMENT_NODE) return false; let el = item; if (blackListSelector.some(i => (item.matches(i) || (el = item.querySelector(i))))) el?.remove(), count++; return true } const observer = new MutationObserver((mutationsList) => { for (let mutation of mutationsList) { killTarget(mutation.target) for (const item of mutation.addedNodes) { killTarget(item) } } }); observer.observe(document, { childList: true, subtree: true }); window.addEventListener("load", () => { console.log(`[-] 文库净化:共清理掉 ${count} 个弹窗~`); }); let pageData, pureViewPageData; let readerdata = GM_getValue('readerinfo'); Object.defineProperty(unsafeWindow, 'pageData', { set: v => pageData = v, get() { if (!pageData) return pageData; // 启用 VIP if ('vipInfo' in pageData) { pageData.vipInfo.global_svip_status = 1; pageData.vipInfo.global_vip_status = 1; pageData.vipInfo.isVip = 1; pageData.vipInfo.isWenkuVip = true; } if ('readerInfo' in pageData && pageData?.readerInfo?.htmlUrls?.json) { if (readerdata) { pageData.readerInfo = readerdata; } else { pageData.readerInfo.showPage = pageData.readerInfo.htmlUrls.json.length; } } if ('appUniv' in pageData) { // 取消百度文库对谷歌、搜狗浏览器 referrer 的屏蔽 pageData.appUniv.blackBrowser = []; // 隐藏 APP 下载按钮 pageData.viewBiz.docInfo.needHideDownload = true; } return pageData } }) Object.defineProperty(unsafeWindow, 'pureViewPageData', { set: v => pureViewPageData = v, get() { if (!pureViewPageData) return pureViewPageData; // 去除水印,允许继续阅读 if ('customParam' in pureViewPageData) { pureViewPageData.customParam.noWaterMark = 1; pureViewPageData.customParam.visibleFoldPage = 1; } if ('readerInfo2019' in pureViewPageData) { pureViewPageData.readerInfo2019.freePage = pureViewPageData.readerInfo2019.page; } return pureViewPageData } }) } function addDownloadBtn(wenkuid) { setTimeout(function(){ if (!unsafeWindow?.readerinfobtn) { var btn = document.createElement('div'); btn.innerHTML = `