// ==UserScript== // @name 迅雷云盘获取直链 // @namespace http://tampermonkey.net/ // @version 1.3.5 // @description 获取迅雷云盘的直接下载链接,可利用本地播放器看视频,可利用其他工具下载(如浏览器下载,idman,curl命令行,Xdown,Motrix,Aria2) // @author bleu // @license MIT // @icon https://img-vip-ssl.a.88cdn.com/img/xunleiadmin/5fb4b23888a05.png // @supportURL https://greasyfork.org/zh-CN/scripts/431256/feedback // @match https://pan.xunlei.com/* // @grant none // @require https://cdn.bootcdn.net/ajax/libs/limonte-sweetalert2/11.1.0/sweetalert2.all.min.js // @require https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js // @require https://cdn.bootcdn.net/ajax/libs/clipboard.js/2.0.8/clipboard.min.js // @downloadURL none // ==/UserScript== (function () { 'use strict'; var local_path; const originFetch = fetch; var reqHeaders, filesURL; Object.defineProperty(window, "fetch", { configurable: true, enumerable: true, // writable: true, get() { return (url, options) => { if (url.indexOf('https://api-pan.xunlei.com/drive/v1/files?limit=100&') === 0) { filesURL = url; reqHeaders = options.headers; //console.log(reqHeaders) } return originFetch(url, options) } } }) var arryIndex; var fileArry; var filetxt; var temp_path; var running = { 'runStatus': false, 'successNum': 0, 'failNum': 0, 'exit': false, 'resultNum': 0, 'needHandle': true, } var $BleuButton, $swalHtml; var main = { addCssStyle() { let cssStyle = ` .btn_bleu{width: 250px;font-size: 20px;padding: 10px 25px;cursor: pointer;text-align: center;text-decoration: none;outline: none;color: #fff;background-color: #008CBA;border: none;border-radius: 100px;display:block;margin:12px auto} .btn_bleu:hover{background-color: #008CEA} .btn_bleu:active{background-color: #008CEA;box-shadow: 0 5px #666;transform: translateY(4px)} .bleu_sa_close {width: 30px;height: 30px;font-size: 30px;} .bleu_sa_title {font-size: 30px;} .bleu_sa_container{margin: 20px 0 0;} .bleu_sa_popup {padding: 0 0 0;} .bleu_a{text-decoration: underline;color: #008CBA;font-size: 20px;} .bleu_a:hover{color: #008CEA} .bleu_sa_title_min{font-size: 20px;padding: 0;} .bleu_sa_popup_min{padding: 0 0 0;text-align-last: right;width: fit-content;} `; let style = document.createElement('style'); style.innerHTML = cssStyle; document.querySelector('head').appendChild(style); }, addElements() { $BleuButton = $('
'); let inputValue = localStorage.getItem("local_path") || 'D:\\Downloads'; let $BleuInput = $(` `); $('div.pan-list-menu').prepend($BleuButton); $('.pan-list-menu__wrapper').prepend($BleuInput); $swalHtml = $(` `) }, addButtonEvent() { $BleuButton.on('click', async function () { main.swalForInfo('==获取直链中,请等待==', '', ''); if (running.runStatus) { return } local_path = $('#bleu_inp').val(); localStorage.setItem("local_path", local_path); try { running.needHandle && await main.getAllInfo(); } catch (error) { console.log(error); main.swalForInfo('==请刷新页面重新尝试!==', '', ''); return; } swal.fire({ title: `成功${running.successNum}条;失败${running.failNum}条`, html: $swalHtml, type: 'success', width: 400 + 'px', showConfirmButton: false, showCloseButton: true, allowOutsideClick: false, customClass: { title: 'bleu_sa_title', popup: 'bleu_sa_popup', closeButton: 'bleu_sa_close', htmlContainer: 'bleu_sa_container', }, }) $('.btn_bleu').on('click', function (item) { let temp = item.target.defaultValue; main.getCollatedData(temp) }) }) }, setInitValue() { arryIndex = 0; fileArry = []; filetxt = []; temp_path = ''; running.runStatus = true; running.successNum = 0; running.failNum = 0; running.resultNum = 0; running.needHandle = false; $('.pan-list-item').on('click', function () { running.needHandle = true; }) $('.pan-list-item a').on('click', function () { running.needHandle = true; }) $('.td-breadcrumb__item a').on('click', function () { running.needHandle = true; }) }, async getAllInfo() { main.setInitValue(); await main.getFileSign(); if (running.exit) { running.exit = false; main.swalForInfo('==请刷新页面重新尝试!==', '', ''); return; } $('li.pan-list-item').each((index, item) => { if (item.getAttribute('class') === 'pan-list-item') { delete(fileArry[0][index]); } }); await main.getAllFiles(fileArry[0]); running.runStatus = false; running.resultNum = running.successNum + running.failNum; }, async getAllFiles(loopArry) { for (let index = 0; index < loopArry.length; index++) { if (loopArry[index]) { if (loopArry[index].kind === 'drive#file') { await main.getDirectLink(loopArry[index].id); } if (loopArry[index].kind === 'drive#folder') { temp_path += `\\${loopArry[index].name}`; await main.getFileSign(loopArry[index]); await main.getAllFiles(fileArry[arryIndex - 1]); } } } temp_path = temp_path.substring(0, temp_path.lastIndexOf('\\')); }, getFileSign(folder) { return new Promise((resolve, reject) => { let runURL; if (folder) { runURL = `https://api-pan.xunlei.com/drive/v1/files?limit=100&parent_id=${folder.id}&filters={"phase":{"eq":"${folder.phase}"},"trashed":{"eq":${folder.trashed}}}&with_audit=true`; runURL = encodeURI(runURL); } else { runURL = filesURL; } fileArry[arryIndex] = []; $.ajax({ type: "get", timeout: 2000, headers: reqHeaders, url: runURL, dataType: "json", success: function (data, textStatus) { data.files.forEach((item) => { let temp = { 'kind': item.kind, 'id': item.id, 'name': item.name, 'phase': item.phase, 'trashed': item.trashed }; fileArry[arryIndex].push(temp); }); arryIndex++; resolve(textStatus); }, error: function (err) { runURL === filesURL ? running.exit = true : running.exit = false; reject(err); } }); }); }, getDirectLink(sign) { return new Promise((resolve, reject) => { $.ajax({ type: "get", timeout: 2000, headers: reqHeaders, url: `https://api-pan.xunlei.com/drive/v1/files/${sign}`, dataType: "json", success: function (data, textStatus) { running.successNum++; let temp = { 'name': data.name, 'link': data.web_content_link, 'path': local_path + temp_path }; filetxt.push(temp); resolve(textStatus); }, error: function (err) { running.failNum++; reject(err); } }); }); }, _downFlie(fnmae, data) { var elementA = document.createElement('a'); elementA.download = fnmae; elementA.style.display = 'none'; var blob = new Blob([data]); elementA.href = URL.createObjectURL(blob); document.body.appendChild(elementA); elementA.click(); document.body.removeChild(elementA); }, async getCollatedData(dataType) { if (running.resultNum === 0) { return; } if (dataType.match('发送')) { main.swalForInfo('==导入任务中,请等待==', '', ''); } var swalTitle = ''; let nameLinkTxt = ''; if (dataType.match('播放')) { nameLinkTxt = '#EXTM3U\n' } filetxt.forEach(async (item) => { if (dataType.match('发送')) { return } if (dataType.match('迅雷直链')) { nameLinkTxt += `${item.name}\n${item.link}\n`; } if (dataType.match('idman')) { nameLinkTxt += `idman /d "${item.link}" /p "${item.path}" /f "${item.name}" /a&`; } if (dataType.match('curl')) { nameLinkTxt += `echo 正在下载这个文件:&echo "${item.path}\\${item.name}"&curl -L "${item.link}" -o "${item.path}\\${item.name}"\n\n`; } if (dataType.match('Xdown')) { nameLinkTxt += `aria2c "${item.link}" --dir "${item.path}" --out "${item.name}"\n`; } if (dataType.match('播放')) { nameLinkTxt += `#EXTINF:-1 ,${item.name}\n${item.link}\n`; } }); if (dataType.match('Xdown') || dataType.match('迅雷直链')) { new ClipboardJS('.btn_bleu.xdown', { text: function () { return nameLinkTxt; } }); main.swalForInfo('复制链接成功!', 1000, 'top-end'); } else if (dataType.match('发送')) { let titleTip = dataType.match('Aria2') ? 'Aria2' : 'Motrix'; let RPCport = dataType.match('Aria2') ? '6800' : '16800'; swalTitle = `导入成功,请到${titleTip}查看任务!`; for (let index = 0; index < filetxt.length; index++) { try { await main.sendDataByRPC(index, RPCport); } catch (error) { console.log(error); swalTitle = `导入失败,请打开${titleTip}!`; break; } } main.swalForInfo(swalTitle, 3000, 'top-end'); } else { let filenam = `${dataType.replace('.txt','')}${(new Date()).valueOf()}.txt`; if (dataType.match('播放')) { filenam = `迅雷云盘播放列表.m3u`; } this._downFlie(filenam, nameLinkTxt); } }, swalForInfo(satitle, satime, saposition) { Swal.fire({ title: satitle, position: saposition, showConfirmButton: false, timer: satime, customClass: { title: 'bleu_sa_title_min', popup: 'bleu_sa_popup_min' } }) }, sendDataByRPC(index, RPCport) { let aria2port = RPCport || '16800'; let jsonData = { id: new Date().getTime(), jsonrpc: '2.0', method: 'aria2.addUri', params: ["token:", [filetxt[index].link], { dir: filetxt[index].path, out: filetxt[index].name }] } jsonData = JSON.stringify(jsonData); return new Promise((resolve, reject) => { $.ajax({ type: 'post', url: `http://localhost:${aria2port}/jsonrpc`, data: jsonData, dataType: "json", success: function (textStatus) { resolve(textStatus); }, error: function (err) { reject(err); } }); }); }, initUI() { let counter = 20; let listener = setInterval(function () { counter--; if (document.querySelector('.pan-list-item')) { clearInterval(listener); main.addElements(); main.addButtonEvent(); } counter === 0 && clearInterval(listener); }, 200); }, } main.addCssStyle(); main.initUI(); })();