// ==UserScript== // @name 百度网盘直链加速下载(超级svip会员领取器),无需关注公众号,直接下载就可以! // @namespace tamp.catboxhub.com // @antifeature membership // @version 0.3.9 // @author 资源好又多 // @description 先看详情再使用!!先看详情再使用!!先看详情再使用!!先看详情再使用!!先看详情再使用!!先看详情再使用!!先看详情再使用!!先看详情再使用!! // @icon data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAABHPGVmAAABBVBMVEUAAAB0rNJ2s9R0stJ2tNV3s9R5s9l2s9R2stJ3s9R2s9R3stR2s9N2stN2s9N3s9R2stR3stJ3s9R2s9R1sNN3s9R2s9R2stN3s9R2stR2s9R3s9R2stN3stR0sdV2s9R2s9R2s9N3s9N3stN2s9N2s9R2s9R3s9J3stV4stR2stN3s9T///9mlbD8/f58ttZomrbf7fX5/P3q8/jN4/CGvNmy1Oer0OSgy+KPwdxtoL2BudhwqMb1+fzZ6vPE3+2Kvtp0rMzt9frv9vre6O6Vw910rs/k8PfQ3+eax+COs8iCqb9vm7VpmLLm7fLT5vJ3obm82erC1eC80dy0zNmausykwNAwUSvcAAAAK3RSTlMABewNNvYIix/m4pNwYfnwTxTXyyef3cS5roN4QvMa0r+0p5pnWkk7LizQzqkA9AAABFhJREFUaN61mdlW4kAQhisbJGEH2RkFBQSrE1kEBRXGfcZldNb3f5Q5Os7pEOjO1n533PCd6r+rOumAX6ReMtEs4Ttys1hTFRCHtK12EgUN10jni+19PQbRyXXjFQOZyOVER4+o2K7nZfQgU4r3whtiW3Fq4KLthgxIaiSowocmmwvu2NozMRByVQ1aRsrAwKTjShBFv4qhKDR8b2ilXcKQyDXdZx2JDIZGa235ao08RsL0tkiNAkZE7ngFs3+AkTFSEteRzaAAtDq3DuqIRpZdS+MABSGnWLnkCigMs8vYWHkUiJnb2OcJFEplg0VqZ1AsifVY+iUUTCa1Vojn3D08nU2fx+SNy8X3m8mh50x2D5gU8jk9WQ7JCuOj48/IJ+46Bw1+FcfDc7LG6O77BHl8UlcWq4g8JkPC4PIr8sgrzlY3eSs1HREm9pK7ZknqiPFa5PPRiPAY8oop6zQRmVPH0CZ8xjecVOg2jnPiuCOejGbIpPU/lW2ZvVYLwoHG773B6uyte2QTPwzZtRTfJzx7+h4TnyzZ7b/9JukyV2s28iuxT/i7WGLGfvhMfDNm9n4h9hp7BRmcnBP/LJGB8Rq9ajBTJwG4YnW+9rpeHWRwcxVEMpoigz0JgDlSpiQQz6e4maYOUGBJhsEkY1avmCpI2uZAJjMSENYuTneht3FiHS/pKRV5f7UhuekAuaMG/wyZyW/I/XBBQnHJklSh6VZ8vSIhYUl2oORu80siWmKA+wAZE+ESBAF5UK6OTiaHnpIpiYh9Nz31kEwuSWRGixlfMrWJAMYznuR0QYSw+MyRzMZiJPaSIaFHYQQYRz7IroeTCLDmWAaaHyIZ3ayMleKHSOwpUipQEymhHCFlF1Rn8PaHSJKgpF3PJ+IlWYA8/TW5FiqhT3fO5C++iJXQt622Q/J7JGp3HTteHhSAfdqOt3NR63V+T5+I6gCgl6l0fi9Icj2nV18N16vvmfXTFtLw92e039/eGjsZahm8iMje/mlduO4+9JKzlIdhdMmXlwH9y/76G/bceryOumLfHiy6Wi34R0+jktuB9fhrHEVz/uXBorGns/DOLlIuBtbTw69voeO4/vNoDW5pJ+bgHVXDlVqsp5ffP8J4xj/uH5+swQUthN7gKLvoZP5kRcDpwIO+4/ZcRidn80F4xRk6qAElV8VVLsJ5BvOzW3Rg6tRBUxFMlhporwimCqsoBfGOkgouGrJoh1aX3BKplhYsqSiwht4S68j3YANbpkiHvM/43CsiFnqNyqBjCAud/Rk4lhLVkzUFmEh1MY69GPDICshFq8W8PsSbkTOnebCIdSNa5JQC3uQqkXqQ9gffEv6DvFbpgU9iqULIuVtXwD9b8TDFVFUJAqHmgyrMLARGSZY/BVAc1HQIg55q+dSky8m+BCFR1KIfRyubg0hsJwuGxqlB3on3IToxNbnXNNO4jlEu1hsKCELS1W57r7pj4DuZncpuMqvq/gx/AWOzQlgCEoTLAAAAAElFTkSuQmCC // @run-at document-end // @require https://lib.baomitu.com/jquery/3.6.0/jquery.min.js // @resource ElementPlusCSS https://lib.baomitu.com/element-plus/2.2.2/index.min.css // @connect * // @connect 127.0.0.1 // @connect localhost // @connect baidu.com // @connect baidupcs.com // @connect pandownload.net // @connect bdjs.lol // @connect d.baiduyunpcs.xyz // @connect speedownload.dzp.me // @grant GM_openInTab // @grant GM_addStyle // @grant GM_getResourceURL // @grant GM_getResourceText // @grant GM_getValue // @grant GM_setValue // @grant GM_xmlhttpRequest // @grant unsafeWindow // @match *://pan.baidu.com/disk/main* // @match *://yun.baidu.com/disk/main* // @match *://wangpan.baidu.com/disk/main* // @match *://pan.baidu.com/disk/home* // @match *://yun.baidu.com/disk/home* // @match *://wangpan.baidu.com/disk/home* // @match *://pan.baidu.com/s/* // @match *://yun.baidu.com/s/* // @match *://pan.baidu.com/share/link?* // @match *://yun.baidu.com/share/link?* // @match *://pan.baidu.com/play/video* // @match *://yun.baidu.com/play/video* // @match *://pan.baidu.com/share/init* // @match *://yun.baidu.com/share/init* // @downloadURL https://update.greasyfork.icu/scripts/455799/%E7%99%BE%E5%BA%A6%E7%BD%91%E7%9B%98%E7%9B%B4%E9%93%BE%E5%8A%A0%E9%80%9F%E4%B8%8B%E8%BD%BD%28%E8%B6%85%E7%BA%A7svip%E4%BC%9A%E5%91%98%E9%A2%86%E5%8F%96%E5%99%A8%29%2C%E6%97%A0%E9%9C%80%E5%85%B3%E6%B3%A8%E5%85%AC%E4%BC%97%E5%8F%B7%EF%BC%8C%E7%9B%B4%E6%8E%A5%E4%B8%8B%E8%BD%BD%E5%B0%B1%E5%8F%AF%E4%BB%A5%EF%BC%81.user.js // @updateURL https://update.greasyfork.icu/scripts/455799/%E7%99%BE%E5%BA%A6%E7%BD%91%E7%9B%98%E7%9B%B4%E9%93%BE%E5%8A%A0%E9%80%9F%E4%B8%8B%E8%BD%BD%28%E8%B6%85%E7%BA%A7svip%E4%BC%9A%E5%91%98%E9%A2%86%E5%8F%96%E5%99%A8%29%2C%E6%97%A0%E9%9C%80%E5%85%B3%E6%B3%A8%E5%85%AC%E4%BC%97%E5%8F%B7%EF%BC%8C%E7%9B%B4%E6%8E%A5%E4%B8%8B%E8%BD%BD%E5%B0%B1%E5%8F%AF%E4%BB%A5%EF%BC%81.meta.js // ==/UserScript== (function () { (() => { var i; var j; var t; var table = []; for (i = 0; i < 256; i++) { t = i; for (j = 0; j < 8; j++) { t = t & 1 ? t >>> 1 ^ 0xEDB88320 : t >>> 1; } table[i] = t; } return table; })(); function isJSON(str) { if (typeof str == 'string') { try { var obj = JSON.parse(str); return true; } catch (e) { return false; } } } var tools = { isJSON: isJSON, getFinalUrl: function (url) { return new Promise(function (resolve, reject) { GM_xmlhttpRequest({ method: "HEAD", url, onload: function (response) { resolve(response.finalUrl); }, onerror: function (err) { reject(new Error(err)); } }); }); }, getAccelerate: function (url) { return new Promise(function (resolve, reject) { const ElementPlus = unsafeWindow.ElementPlus; const accelerateURL = GM_getValue("accelerateURL", "").replaceAll(" ",""); GM_xmlhttpRequest({ method: "HEAD", url, onload: function (response) { let responseHeaders = response.responseHeaders.toLowerCase(); let finalUrl = response.finalUrl; console.log(finalUrl); if(finalUrl.match(/&fn=(.*)&rtype/).length == 0){ let result = {}; result.code = -1; result.errMsg = "无法获取文件名称,更新Chroe再试"; result.title = "网盘下载"; return resolve(result); } let filename = finalUrl.match(/&fn=(.*)&rtype/)[1]; let decodeFilename = decodeURIComponent(filename.replaceAll('+','%20')); if (response.status != 200) { let result = {}; result.code = -1; result.errMsg = "无法获取文件的细息"; result.title = decodeFilename; return resolve(result); } let Notification = ElementPlus.ElNotification({ title: decodeFilename, message: '正在请求加速链接,请耐等待...', duration: 0, type: 'warning' }); if(responseHeaders.match(/content-md5: (.*)/).length == 0){ let result = {}; result.code = -1; result.errMsg = "无法获取文件MD"; result.title = decodeFilename; return resolve(result); } let contentMD5 = responseHeaders.match(/content-md5: (.*)/)[1]; let contentLength = responseHeaders.match(/content-length: (.*)/)[1]; let data = {}; data.dlink = url; data.md5 = contentMD5; data.size = contentLength; data.name = filename; GM_xmlhttpRequest({ method: "POST", url: accelerateURL, data: JSON.stringify(data), onload: function (response) { if (response.status != 200) { Notification.close(); let result = {}; result.code = -10; result.errMsg = "请求加速链接失败"; result.title = decodeFilename; return resolve(result); } if (response.responseText.length == 0) { Notification.close(); let result = {}; result.code = -7; result.errMsg = "加速链接未返回任何内容"; result.title = decodeFilename; return resolve(result); } if (!isJSON(response.responseText)) { Notification.close(); let result = {}; result.code = -2; result.errMsg = "无效的加速链接"; result.title = decodeFilename; return resolve(result); } let ret = JSON.parse(response.responseText); if (ret.code != 0) { Notification.close(); let result = {}; result.code = -3; result.errMsg = ret.message == undefined || ret.message == "" ? "服务器未返回任何有效信息" : ret.message; result.title = decodeFilename; return resolve(result); } let dlink = ret.data.urls[0].url; if (dlink == undefined || dlink == "") { Notification.close(); let result = {}; result.code = -6; result.errMsg = "该加速链接未返回有效的下载链接"; result.title = decodeFilename; return resolve(result); } Notification.close(); let result = {}; result.code = ret.code; result.message = ret.message; result.url = dlink; result.ua = ret.data.ua; result.split = ret.data.split; result.pro = ret.data.pro; result.name = decodeFilename; return resolve(result); }, onerror: function (err) { Notification.close(); let result = {}; result.code = -10; result.errMsg = "请求加速链接失败"; result.title = decodeFilename; return resolve(result); } }); } }); }); }, getCookie: function (name) { const strCookie = document.cookie; const cookieList = strCookie.split(';'); for (let i = 0; i < cookieList.length; i++) { const arr = cookieList[i].split('='); if (name === arr[0].trim()) { return arr[1]; } } return null; }, browserDownload: function (url) { const iframe = document.createElement("iframe"); iframe.style.display = "none"; iframe.src = url.replace("http://", "https://"); document.body.appendChild(iframe); setTimeout(() => { iframe.remove(); }, 2 * 60 * 1000); }, aria2Download: function (aria2) { unsafeWindow.ElementPlus; const RpcUrl = "http://" + GM_getValue("RpcHost", "localhost") + ":" + GM_getValue("RpcPort", "6800") + GM_getValue("RpcPath", "/jsonrpc"); const token = GM_getValue("RpcToken", ""); const downDir = GM_getValue("Aria2DownloadDir", "C:/Downloads"); const userAgent = aria2.userAgent; let ariaData = { id: new Date().getTime(), jsonrpc: '2.0', method: 'aria2.addUri', params: [`token:${token}`, [aria2.url], { 'dir': downDir.replaceAll("\\", "/") + aria2.dir, 'out': decodeURIComponent(aria2.fileName), 'max-connection-per-server': aria2.split, 'header': [`User-Agent: ${userAgent}`, `Cookie:${aria2.cookie}`] }] }; GM_xmlhttpRequest({ method: "POST", url: RpcUrl, data: JSON.stringify(ariaData), onload: function () { unsafeWindow.ElementPlus.ElNotification({ type: 'success', title: decodeURIComponent(aria2.fileName), message: '文件已加入 Aria2 下载队列', duration: 3000 }); aria2.notify.close(); }, onerror: function () { unsafeWindow.ElementPlus.ElNotification({ type: 'error', title: decodeURIComponent(aria2.fileName), message: '推送至 Aria2 时发生错误,请检查配置', duration: 3000 }); aria2.notify.close(); } }); } }; // 初始化 Jquery var $$1 = window.$; var Adblock = { init: function () { $$1('.wp-s-header-cert__ee-cert-tilte.u-popover__reference').remove(); $$1('.nd-cus-btn.wp-s-disk-header__right-item').remove(); $$1('.ad-platform-tips.ad-multi-tips').remove(); $$1('.init-docs .phone-banner').remove(); $$1('.gOIbzPb').remove(); $$1('#web-right-view').remove(); } }; var scriptName = "网盘下载器"; var title = scriptName + " v0.3.9"; // 初始化库 var $ = window.$; //var PonyfillCDN = "https://fastly.jsdelivr.net/npm/web-streams-polyfill@2.0.2/dist/ponyfill.min.js"; //var StreamSaverCDN = "https://fastly.jsdelivr.net/npm/streamsaver@2.0.6/StreamSaver.min.js"; var VueCDN = "https://lib.baomitu.com/vue/3.2.36/vue.global.prod.min.js"; var ElementPlusCDN = "https://lib.baomitu.com/element-plus/2.2.2/index.full.min.js"; // 过滤广告 Adblock.init(); // 新版Vue 路由Hook - 备用 if (unsafeWindow.globalVue != undefined) { var ElementUI = unsafeWindow.globalVue.$options._base.prototype; unsafeWindow.globalVue._router.afterHooks.push(router => { console.log(router); }); } // 判断当前页面 const URL_HREF = unsafeWindow.location.href; const MATCHS = { 'https?://(pan|yun).baidu.com/disk/main.*': 'pan', 'https?://(pan|yun).baidu.com/disk/home.*': 'old', 'https?://(pan|yun).baidu.com/s/.*': 'share', 'https?://(pan|yun).baidu.com/share/link/?.*': 'share', 'https?://(pan|yun).baidu.com/play/video/.*': 'video' }; let currentPage = 'pan'; for (let match in MATCHS) { if (new RegExp(match).test(URL_HREF)) { currentPage = MATCHS[match]; break; } } // 初始化打包下载 /* $.getScript(PonyfillCDN, function () { $.getScript(StreamSaverCDN, function () { const iframe = document.createElement("iframe"); iframe.style.display = "none"; iframe.src = "https://qdall01.baidupcs.com"; iframe.onload = function () { console.log("IFrame加载成功") unsafeWindow.downloadSingle = function (url, filename, filesize) { const fileStream = unsafeWindow.streamSaver.createWriteStream(filename, { size: filesize }) fetch(url) .then(response => { if (response.status != 200) { response.json().then(json => console.log(json)); return; } const readableStream = response.body unsafeWindow.writer = fileStream.getWriter() const reader = response.body.getReader() const pump = () => reader.read() .then(response => response.done ? unsafeWindow.writer.close() : unsafeWindow.writer.write(response.value).then(pump)) pump() }); } unsafeWindow.downloadBatch = function (downloadList) { console.log("Batch Download", downloadList) const firstFile = downloadList.metaList[downloadList.dlinkList[0].fs_id] let totalSize = 0; for (let index in downloadList.dlinkList) { let fileList = downloadList.dlinkList[index]; let meta = downloadList.metaList[fileList.fs_id]; totalSize += meta.size; } console.log(totalSize) const fileStream = unsafeWindow.streamSaver.createWriteStream(firstFile.server_filename + "等其他(" + (downloadList.dlinkList.length - 1) + ")个文件.zip", { size: totalSize }) const readableZipStream = new ZIP({ async pull(ctrl) { for (let index in downloadList.dlinkList) { let fileList = downloadList.dlinkList[index]; let metaList = downloadList.metaList[fileList.fs_id]; let dlink = fileList.dlink.replace("http://", "https://") + "&origin=dlna"; let finalUrl = await Tools.getFinalUrl(dlink) console.log(finalUrl) const res = await fetch(finalUrl) const stream = () => res.body const name = metaList.path ctrl.enqueue({ name, stream }) } ctrl.close() } }) // console.log(readableZipStream) // more optimized // less optimized const writer = fileStream.getWriter() const reader = readableZipStream.getReader() const pump = () => reader.read() .then(res => res.done ? writer.close() : writer.write(res.value).then(pump)) pump() } } document.body.appendChild(iframe); }) }) */ function createApp(className, html) { var ElementPlus = unsafeWindow.ElementPlus; var Vue = unsafeWindow.Vue; var render = html + ` 检查跟 Aria2 的连通性 `; $(className).append(render); const App = { setup() { return { dialogVisible: Vue.ref(false), Setting: Vue.reactive({ downType: GM_getValue("downType", "browser"), disableAccelerate: Vue.ref(false), accelerateInput: Vue.ref(GM_getValue("accelerateURL", "")), RpcPathInput: Vue.ref(GM_getValue("RpcPath", "/jsonrpc")), RpcHostInput: Vue.ref(GM_getValue("RpcHost", "localhost")), RpcPortInput: Vue.ref(GM_getValue("RpcPort", "6800")), RpcTokenInput: Vue.ref(GM_getValue("RpcToken", "")), Aria2DownloadDir: Vue.ref(GM_getValue("Aria2DownloadDir", "C:/Downloads")), Aria2MaxConnection: Vue.ref(GM_getValue("Aria2MaxConnection", "16")), activeName: Vue.ref('TabSetting') }) }; }, methods: { OpenDialog() { this.dialogVisible = true; this.Setting.disableAccelerate = GM_getValue("disableAccelerate", false); this.Setting.accelerateInput = GM_getValue("accelerateURL", ""); this.Setting.downType = GM_getValue("downType", "browser"); this.Setting.RpcPathInput = GM_getValue("RpcPath", "/jsonrpc"); this.Setting.RpcHostInput = GM_getValue("RpcHost", "localhost"); this.Setting.RpcPortInput = GM_getValue("RpcPort", "6800"); this.Setting.RpcTokenInput = GM_getValue("RpcToken", ""); this.Setting.Aria2DownloadDir = GM_getValue("Aria2DownloadDir", "C:/Downloads"); this.Setting.Aria2MaxConnection = GM_getValue("Aria2MaxConnection", "16"); }, CloseDialog() { this.dialogVisible = false; }, CheckAria2(){ const msg = ElementPlus.ElMessage({ type: 'info', message: `正在尝试连接Aria2中...`, }) const RpcUrl = "http://" + this.Setting.RpcHostInput + ":" + this.Setting.RpcPortInput + this.Setting.RpcPathInput; const token = this.Setting.RpcTokenInput; let ariaData = { id: new Date().getTime(), jsonrpc: '2.0', method: 'aria2.getVersion', params: [`token:${token}`, [RpcUrl], { }] }; GM_xmlhttpRequest({ method: "POST", url: RpcUrl, data: JSON.stringify(ariaData), onload: function () { msg.close() ElementPlus.ElMessage({ type: 'success', message: `已成功连接 Aria2`, }) }, onerror: function () { msg.close() ElementPlus.ElMessage({ type: 'error', message: `无法连接至 Aria2`, }) } }); }, SaveAccelerateURL() { this.dialogVisible = false; GM_setValue("disableAccelerate", this.Setting.disableAccelerate); GM_setValue("accelerateURL", this.Setting.accelerateInput); GM_setValue("downType", this.Setting.downType); GM_setValue("RpcPath", this.Setting.RpcPathInput); GM_setValue("RpcHost", this.Setting.RpcHostInput); GM_setValue("RpcPort", this.Setting.RpcPortInput); GM_setValue("RpcToken", this.Setting.RpcTokenInput); GM_setValue("Aria2DownloadDir", this.Setting.Aria2DownloadDir); GM_setValue("Aria2MaxConnection", this.Setting.Aria2MaxConnection); ElementPlus.ElMessage({ message: '已保存该设置', type: 'success' }); } } }; const app = Vue.createApp(App); app.use(ElementPlus); app.mount("#app"); } // 加载 Vue3 + ElementPlus GM_addStyle(GM_getResourceText("ElementPlusCSS")); $.getScript(VueCDN, function () { console.log("[" + scriptName + "] Vue 加载成功"); $.getScript(ElementPlusCDN, function () { console.log("[" + scriptName + "] ElementPlus 加载成功"); // if (currentPage == 'pan') { // createApp('.wp-s-aside-nav__main-top', ` //
// //
// //

下载设置

//
//
// `); // } // if (currentPage == 'old') { // createApp('.fldwM9jB', ` //
// 下载设置 // `); // } // if (currentPage == 'share') { // createApp('.bar .x-button-box', ` //
// 下载设置 // `); // } }); }); async function GlobalDownload(params) { const ElementPlus = unsafeWindow.ElementPlus; const accelerateURL = GM_getValue("accelerateURL", ""); const disableAccelerate = GM_getValue("disableAccelerate", false); const downType = GM_getValue("downType", "browser"); const maxConnection = GM_getValue("Aria2MaxConnection", "16"); let baiduyunPlugin_BDUSS = JSON.parse(unsafeWindow.localStorage.baiduyunPlugin_BDUSS ? unsafeWindow.localStorage.baiduyunPlugin_BDUSS : '{"baiduyunPlugin_BDUSS":""}'); let BDUSS = baiduyunPlugin_BDUSS.BDUSS; // 单文件下载 if (params.type == 0) { // 无加速链接 if (accelerateURL == "" || disableAccelerate) { if (downType == "browser") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 浏览器 下载文件', duration: 1000 }); } for (let dlink of params.dlinkList) { let finalUrl = await tools.getFinalUrl(dlink); tools.browserDownload(finalUrl); } } if (downType == "aria2") { // Aria2下载 if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 Aria2 下载文件', duration: 1000 }); } for (let dlink of params.dlinkList) { let finalUrl = await tools.getFinalUrl(dlink); tools.aria2Download({ cookie: `BDUSS=${BDUSS}`, url: finalUrl, fileName: finalUrl.match(/&fn=(.*)&rtype=/)[1], dir: '/', split: maxConnection, userAgent: navigator.userAgent }); } } } // 有加速链接 if (accelerateURL != "" && !disableAccelerate) { if (downType == "browser") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 浏览器 下载文件', duration: 1000 }); } for (let dlink of params.dlinkList) { tools.getAccelerate(dlink).then(function (result) { if (result.code != 0) { // 请求加速链接失败的话,就重试一次 if (result.code == -10) { console.log("重试") tools.getAccelerate(dlink).then(function (result) { if (result.code != 0) { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } else { ElementPlus.ElNotification({ title: result.name, message: result.message, duration: 1500, type: 'success' }); tools.browserDownload(result.url); } }); } else { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } } else { ElementPlus.ElNotification({ title: result.name, message: result.message, duration: 1500, type: 'success' }); tools.browserDownload(result.url); } }); } // 遍历urls开始下载文件 } if (downType == "aria2") { // Aria2下载 let urls = []; if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 Aria2 下载文件', duration: 1000 }); } for (let dlink of params.dlinkList) { tools.getAccelerate(dlink).then(function (result) { if (result.code != 0) { // 请求加速链接失败的话,就重试一次 if (result.code == -10) { console.log("重试") tools.getAccelerate(dlink).then(function (result) { if (result.code != 0) { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } else { ElementPlus.ElNotification({ title: result.name, message: result.message, duration: 2000, type: 'success' }); let meta = {}; meta.url = result.url; meta.name = result.name; tools.aria2Download({ url: meta.url, fileName: meta.name, dir: '/', split: result.split, userAgent: result.ua }); } }); } else { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } } else { ElementPlus.ElNotification({ title: result.name, message: result.message, duration: 1500, type: 'success' }); let meta = {}; meta.url = result.url; meta.name = result.name; tools.aria2Download({ url: meta.url, fileName: meta.name, dir: '/', split: result.split, userAgent: result.ua }); } }); } } } } // 盘内文件夹下载 if (params.type == 1) { // 无加速链接 if (accelerateURL == "" || disableAccelerate) { if (downType == "browser") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 浏览器 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "GET", url: "/api/download?clienttype=8&app_id=250528&web=1&fidlist=[" + file.fs_id + "]&type=dlink&vip=2&sign=" + params.sign + "×tamp=" + params.timestamp, onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return -1; } let dlinkList = []; for (let list of data.dlink) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } GlobalDownload({ type: 0, dlinkList: dlinkList, notification: false }); } }); } if (file.isdir == 1) { GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/api/list?clienttype=0&app_id=250528&web=1&order=name&desc=1&dir=" + encodeURIComponent(file.path) + "&num=100000&page=1", onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 1, sign: params.sign, timestamp: params.timestamp, fileList: list.list, notification: false }); } }); } } } if (downType == "aria2") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 Aria2 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "GET", url: "/api/download?clienttype=8&app_id=250528&web=1&fidlist=[" + file.fs_id + "]&type=dlink&vip=2&sign=" + params.sign + "×tamp=" + params.timestamp, onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return -1; } let dlinkList = []; for (let list of data.dlink) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } for (let dlink of dlinkList) { let finalUrl = await tools.getFinalUrl(dlink); tools.aria2Download({ cookie: `BDUSS=${BDUSS}`, url: finalUrl, fileName: finalUrl.match(/&fn=(.*)&rtype=/)[1], dir: params.dir, split: maxConnection, userAgent: navigator.userAgent }); } } }); } if (file.isdir == 1) { GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/api/list?clienttype=0&app_id=250528&web=1&order=name&desc=1&dir=" + encodeURIComponent(file.path) + "&num=100000&page=1", onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 1, sign: params.sign, timestamp: params.timestamp, fileList: list.list, notification: false, dir: params.dir + file.server_filename + '/' }); } }); } } } } // 有加速链接 if (accelerateURL != "" && !disableAccelerate) { if (downType == "browser") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 浏览器 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "GET", url: "/api/download?clienttype=8&app_id=250528&web=1&fidlist=[" + file.fs_id + "]&type=dlink&vip=2&sign=" + params.sign + "×tamp=" + params.timestamp, onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return -1; } let urls = []; for (let dlinks of data.dlink) { let dlink = dlinks.dlink.replace("http://", "https://") + "&origin=dlna"; let result = await tools.getAccelerate(dlink); if (result.code != 0) { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } else { ElementPlus.ElNotification({ title: result.name, message: result.message, duration: 1500, type: 'success' }); urls.push(result.url); } } // 遍历urls开始下载文件 for (let url of urls) { tools.browserDownload(url); } } }); } if (file.isdir == 1) { GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/api/list?clienttype=0&app_id=250528&web=1&order=name&desc=1&dir=" + encodeURIComponent(file.path) + "&num=100000&page=1", onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 1, sign: params.sign, timestamp: params.timestamp, fileList: list.list, notification: false }); } }); } } } if (downType == "aria2") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 Aria2 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "GET", url: "/api/download?clienttype=8&app_id=250528&web=1&fidlist=[" + file.fs_id + "]&type=dlink&vip=2&sign=" + params.sign + "×tamp=" + params.timestamp, onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return -1; } let urls = []; let dlinkList = []; for (let list of data.dlink) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } for (let dlink of dlinkList) { var result = await tools.getAccelerate(dlink); if (result.code != 0) { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } else { ElementPlus.ElNotification({ title: result.name, message: result.message, duration: 1500, type: 'success' }); let meta = {}; meta.url = result.url; meta.name = result.name; urls.push(meta); } for (let meta of urls) { tools.aria2Download({ url: meta.url, fileName: meta.name, dir: params.dir, split: result.split, userAgent: result.ua }); } } } }); } if (file.isdir == 1) { GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/api/list?clienttype=0&app_id=250528&web=1&order=name&desc=1&dir=" + encodeURIComponent(file.path) + "&num=100000&page=1", onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 1, sign: params.sign, timestamp: params.timestamp, fileList: list.list, notification: false, dir: params.dir + file.server_filename + '/' }); } }); } } } } } // 分享文件夹下载 if (params.type == 2) { // 无加速链接 if (accelerateURL == "" || disableAccelerate) { if (downType == "browser") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 浏览器 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "POST", url: params.url, data: params.data.replace('[fid_list]', '[' + file.fs_id + ']'), onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return params.doError(data.errno); } let dlinkList = []; for (let list of data.list) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } GlobalDownload({ type: 0, dlinkList: dlinkList, notification: false }); } }); } if (file.isdir == 1) { let share_uk = unsafeWindow.locals.get("share_uk"); let primaryid = unsafeWindow.locals.get("shareid"); GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/share/list?uk=" + share_uk + "&shareid=" + primaryid + "&order=name&desc=1&showempty=0&web=1&page=1&num=10000&dir=" + encodeURIComponent(file.path), onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 2, dir: params.dir + file.server_filename + '/', url: params.url, data: params.data, fileList: list.list, notification: false }); } }); } } } if (downType == "aria2") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 Aria2 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "POST", url: params.url, data: params.data.replace('[fid_list]', '[' + file.fs_id + ']'), onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return params.doError(data.errno); } let dlinkList = []; for (let list of data.list) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } for (let dlink of dlinkList) { let finalUrl = await tools.getFinalUrl(dlink); tools.aria2Download({ cookie: `BDUSS=${BDUSS}`, url: finalUrl, fileName: finalUrl.match(/&fn=(.*)&rtype=/)[1], dir: params.dir, split: maxConnection, userAgent: navigator.userAgent }); } } }); } if (file.isdir == 1) { let share_uk = unsafeWindow.locals.get("share_uk"); let primaryid = unsafeWindow.locals.get("shareid"); GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/share/list?uk=" + share_uk + "&shareid=" + primaryid + "&order=name&desc=1&showempty=0&web=1&page=1&num=10000&dir=" + encodeURIComponent(file.path), onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 2, dir: params.dir + file.server_filename + '/', url: params.url, data: params.data, fileList: list.list, notification: false }); } }); } } } } // 有加速链接 if (accelerateURL != "" && !disableAccelerate) { if (downType == "browser") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 浏览器 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "POST", url: params.url, data: params.data.replace('[fid_list]', '[' + file.fs_id + ']'), onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return params.doError(data.errno); } for (let dlinks of data.list) { let dlink = dlinks.dlink.replace("http://", "https://") + "&origin=dlna"; let result = await tools.getAccelerate(dlink); if (result.code != 0) { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } else { ElementPlus.ElNotification({ title: result.name, message: "加速链接已获取,正在加入下载列表...", duration: 1500, type: 'success' }); tools.browserDownload(result.url); } } } }); } if (file.isdir == 1) { let share_uk = unsafeWindow.locals.get("share_uk"); let primaryid = unsafeWindow.locals.get("shareid"); console.log(file.path) GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/share/list?uk=" + share_uk + "&shareid=" + primaryid + "&order=name&desc=1&showempty=0&web=1&page=1&num=10000&dir=" + encodeURIComponent(file.path), onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 2, dir: params.dir + file.server_filename + '/', url: params.url, data: params.data, fileList: list.list, notification: false }); } }); } } } if (downType == "aria2") { if (params.notification == undefined) { ElementPlus.ElNotification({ title: title, message: '正在使用 Aria2 下载文件夹', duration: 1000 }); } for (let file of params.fileList) { if (file.isdir == 0) { GM_xmlhttpRequest({ method: "POST", url: params.url, data: params.data.replace('[fid_list]', '[' + file.fs_id + ']'), onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "下载文件时出错,错误代码:" + data.errno, duration: 3000, type: 'error' }); return params.doError(data.errno); } let urls = []; let dlinkList = []; for (let list of data.list) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } for (let dlink of dlinkList) { var result = await tools.getAccelerate(dlink); if (result.code != 0) { ElementPlus.ElNotification({ title: result.title, message: result.errMsg, duration: 5000, type: 'error' }); } else { ElementPlus.ElNotification({ title: result.name, message: result.message, duration: 1500, type: 'success' }); let meta = {}; meta.url = result.url; meta.name = result.name; urls.push(meta); } for (let meta of urls) { tools.aria2Download({ url: meta.url, fileName: meta.name, dir: params.dir, split: result.split, userAgent: result.ua }); } } } }); } if (file.isdir == 1) { let share_uk = unsafeWindow.locals.get("share_uk"); let primaryid = unsafeWindow.locals.get("shareid"); GM_xmlhttpRequest({ method: "GET", url: "https://pan.baidu.com/share/list?uk=" + share_uk + "&shareid=" + primaryid + "&order=name&desc=1&showempty=0&web=1&page=1&num=10000&dir=" + encodeURIComponent(file.path), onload: function (response) { let list = JSON.parse(response.responseText); if (list.errno != 0) { ElementPlus.ElNotification({ title: file.server_filename, message: "尝试获取文件夹列表时失败,错误代码:" + list.errno, duration: 3000, type: 'error' }); return -1; } GlobalDownload({ type: 2, dir: params.dir + file.server_filename + '/', url: params.url, data: params.data, fileList: list.list, notification: false }); } }); } } } } } } function NewPageDownload() { const nd_download = unsafeWindow.nd_download; nd_download.canShowFail = false; nd_download.dlinkIns.getSign().then(function () { let dlinkIns = nd_download.dlinkIns; let currentFileMetas = nd_download.currentFileMetas; if (!currentFileMetas.length) { return console.error("[Plugin][download] 需要选中至少一个文件!"); } let sign = dlinkIns.sign, timestamp = dlinkIns.timestamp, userInfo = dlinkIns.ctx.userInfo, vipType = userInfo.vipType, vip = void 0 === vipType ? 0 : vipType; let fileList = {}; let fidList = currentFileMetas.map(function (File) { fileList[File.fs_id] = File; return File.fs_id; }); currentFileMetas.map(function (File) { return File.path; }); let includeFolder = currentFileMetas.some(function (File) { return File.isdir; }); if (includeFolder) { let fileList = []; for (let FileMetas of currentFileMetas) { let meta = {}; meta.fs_id = FileMetas.fs_id; meta.isdir = FileMetas.isdir; meta.path = FileMetas.path; meta.server_filename = FileMetas.server_filename; fileList.push(meta); } GlobalDownload({ type: 1, dir: '/', sign: encodeURIComponent(sign), timestamp: timestamp, fileList: fileList }); //downloadFolder(currentFileMetas, sign, timestamp, vip); return console.log("[Plugin][download] 跳转至文件夹下载函数"); } GM_xmlhttpRequest({ method: "GET", url: "/api/download?clienttype=8&app_id=250528&web=1&fidlist=" + JSON.stringify(fidList) + "&type=dlink&vip=" + vip + "&sign=" + encodeURIComponent(sign) + "×tamp=" + timestamp, onload: async function (res) { let data = JSON.parse(res.responseText); if (data.errno !== 0) { ElementUI.$Message({ 'dangerouslyUseHTMLString': true, 'type': 'error', 'message': dlinkIns.setResData(data).show_msg }); return -1; } let dlinkList = []; for (let list of data.dlink) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } GlobalDownload({ type: 0, dlinkList: dlinkList }); } }); }); } // 旧版页面 if (unsafeWindow.require != undefined) { let ctx = unsafeWindow.require("system-core:context/context.js").instanceForSystem; let tip = ctx.ui.tip; ctx.ui.tip = function (e) { return -1 != e.msg.indexOf("下载失败") && (e.msg = ""), -1 != e.msg.indexOf("正在启动网盘客户端") && (e.msg = ""), tip.call(this, e); }, unsafeWindow.require.async("function-widget-1:download/service/guanjiaServerProxy.js", guanjiaServerProxy => { guanjiaServerProxy.sendServer = function () { console.log("[" + scriptName + "] 已禁止调用客户端"); }; }); unsafeWindow.require.async('function-widget-1:download/config.js', config => { [].push.apply(config.directDownloadkeysConfig, config.guanjiaDownloadkeysConig); config.guanjiaDownloadkeysConig = []; }); unsafeWindow.require.async('function-widget-1:download/service/dlinkService.js', dlinkService => { console.log(dlinkService); dlinkService.getDlinkShare = function (data, callback) { this.arguments = arguments; var p = this; let fidList = []; let currentFileMetas = data.list; let shareUrl = dlinkService.URL_DLINK_SHARE + "?sign=" + data.sign + "×tamp=" + data.timestamp + "&channel=chunlei&web=1&app_id=250528&clienttype=12&jsToken=" + unsafeWindow.jsToken; let postData = "encrypt=0&product=share&uk=" + data.share_uk + "&primaryid=" + data.share_id + "&extra=" + encodeURIComponent(JSON.stringify({ sekey: decodeURIComponent(tools.getCookie("BDCLND")) })) + "&fid_list=[fid_list]&vip=2&vcode_input=" + (data.vcode_input == undefined ? "" : data.vcode_input) + "&vcode_str=" + (data.vcode_str == undefined ? "" : data.vcode_str); let includeFolder = currentFileMetas.some(function (File) { return File.isdir; }); if (includeFolder) { let fileList = []; for (let FileMetas of currentFileMetas) { let meta = {}; meta.fs_id = FileMetas.fs_id; meta.isdir = FileMetas.isdir; meta.path = FileMetas.path; meta.server_filename = FileMetas.server_filename; fileList.push(meta); } GlobalDownload({ type: 2, dir: '/', url: shareUrl, data: postData, fileList: fileList, doError: p._doError }); return console.log("[Plugin][download] 跳转至文件夹下载函数"); } for (let meta of currentFileMetas) { let fs_id = meta.fs_id; fidList.push(fs_id); } GM_xmlhttpRequest({ method: "POST", url: shareUrl, data: postData.replace('[fid_list]', JSON.stringify(fidList)), onload: async function (res) { res = JSON.parse(res.responseText); if (res.errno != 0) { return p._doError(res.errno); } let dlinkList = []; for (let list of res.list) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } GlobalDownload({ type: 0, dlinkList: dlinkList }); }, error: function () { p._doError(); } }); }; dlinkService.getDlinkPan = function (fsidList, downType) { this.arguments = arguments; var p = this; unsafeWindow.locals.get("sign1", "sign2", "sign3", "timestamp", function (l, g, f, h) { if (null === p.sign) { var m = ""; try { m = new Function("return " + g)(); } catch (_) { throw new Error(_.message); } if ("function" != typeof m) return void p._doError(); p.sign = encodeURIComponent(p.base64Encode(m(f, l))); } let currentFileMetas = ctx.list.getSelected(); let includeFolder = currentFileMetas.some(function (File) { return File.isdir; }); if (includeFolder) { let fileList = []; for (let FileMetas of currentFileMetas) { let meta = {}; meta.fs_id = FileMetas.fs_id; meta.isdir = FileMetas.isdir; meta.path = FileMetas.path; meta.server_filename = FileMetas.server_filename; fileList.push(meta); } GlobalDownload({ type: 1, dir: '/', sign: p.sign, timestamp: h, fileList: fileList }); //downloadFolder(currentFileMetas, sign, timestamp, vip); return console.log("[Plugin][download] 跳转至文件夹下载函数"); } GM_xmlhttpRequest({ method: "POST", url: dlinkService.URL_DLINK_PAN, data: "app_id=250528&clienttype=8&type=dlink&fidlist=" + fsidList + "&sign=" + p.sign + "×tamp=" + h, onload: async function (res) { res = JSON.parse(res.responseText); if (res.errno != 0) { p._doError(res.errno); return; } let dlinkList = []; for (let list of res.dlink) { let dlink = list.dlink.replace("http://", "https://") + "&origin=dlna"; dlinkList.push(dlink); } GlobalDownload({ type: 0, dlinkList: dlinkList }); }, onerror: function (err) { p._doError(); } }); }); }; }); } // 盘内Hook let HookBaiduNetdisk = new MutationObserver(mutationRecords => { for (let mr of mutationRecords) { for (let node of mr.addedNodes) { if (node.__vue__ !== undefined && node.__vue__ !== null) { var Vue = node.__vue__; if (Vue.$el.className == "nd-download") { unsafeWindow.nd_download = Vue; // 重写下载方 Vue.download = NewPageDownload; } // 过滤广告 if (Vue.$el.className == "web-header-ad-item wp-s-header__right-item") { Vue.conf.text = ""; } if (Vue.$el.className == "nd-unzip") { unsafeWindow.unzip = Vue; console.log(Vue); } } } } }); HookBaiduNetdisk.observe(document, { childList: true, subtree: true }); })();