Greasy Fork is available in English.

百度网盘下载管理器

A download manager for Baidu Yun

Version vom 2020-10-07 05:27:15 UTC. Aktuellste Version

/*!
// ==UserScript==
// @namespace https://dotennin.blogspot.com/
// @name 百度网盘下载管理器
// @description A download manager for Baidu Yun
// @version 1.0
// @author Dotennin
// @license MIT
// @compatible        chrome/83.0.4103.97 passed
// @compatible        edge/83.0.478.54 passed
// @compatible        firefox untested
// @compatible        opera untested
// @compatible        safari untested
// @include https://pan.baidu.com/disk/*
// @connect baidu.com
// @connect qdall01.baidupcs.com
// @resource customStyle https://dotennin.github.io/baidu-pan-downloader/src/style.css
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @grant GM_download
// @grant GM_addStyle
// @grant GM_notification
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_deleteValue
// @run-at document-idle
// ==/UserScript==
 */
!function(e){var t={};function n(o){if(t[o])return t[o].exports;var a=t[o]={i:o,l:!1,exports:{}};return e[o].call(a.exports,a,a.exports,n),a.l=!0,a.exports}n.m=e,n.c=t,n.d=function(e,t,o){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:o})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var o=Object.create(null);if(n.r(o),Object.defineProperty(o,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)n.d(o,a,function(t){return e[t]}.bind(null,a));return o},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=2)}([function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.d(__webpack_exports__,"a",(function(){return InstanceForSystem}));var _gmInterface_gmInterface__WEBPACK_IMPORTED_MODULE_0__=__webpack_require__(1),InstanceForSystem={list:eval("require('system-core:context/context.js')").instanceForSystem.list,autoStart:!0,maxDownloadCount:1,downloadingItems:{},stoppedItems:{},completedItems:{},allDownloads:{},get selectedList(){var e=Object.assign(_gmInterface_gmInterface__WEBPACK_IMPORTED_MODULE_0__.a.getValue("downloadingItems",{}),_gmInterface_gmInterface__WEBPACK_IMPORTED_MODULE_0__.a.getValue("stoppedItems",{}));return _gmInterface_gmInterface__WEBPACK_IMPORTED_MODULE_0__.a.deleteValue("downloadingItems"),_gmInterface_gmInterface__WEBPACK_IMPORTED_MODULE_0__.a.deleteValue("stoppedItems"),this.list.getSelected().filter((function(e){return 1!==e.isdir})).concat(Object.values(e))},get itemsFromQueue(){var e=this,t={},n=Object.keys(Object.assign({},this.downloadingItems,this.completedItems,this.stoppedItems));return Object.keys(this.allDownloads).forEach((function(o){n.includes(o)||(t[o]=e.allDownloads[o])})),t},get downloadable(){return Object.keys(this.downloadingItems).length<this.maxDownloadCount},get currentList(){return this.list.getCurrentList()},stopAll:function(){Object.values(this.downloadingItems).forEach((function(e){e.request.abort()}))}}},function(module,__webpack_exports__,__webpack_require__){"use strict";__webpack_require__.d(__webpack_exports__,"a",(function(){return GM}));var GM={addStyle:function(e){GM_addStyle(e)},deleteValue:function(e){GM_deleteValue(e)},listValues:function listValues(){eval("GM_listValues()")},addValueChangeListener:function(e,t){return GM_addValueChangeListener(e,t)},removeValueChangeListener:function(e){GM_removeValueChangeListener(e)},setValue:function(e,t){GM_setValue(e,t)},getValue:function(e,t){return GM_getValue(e,t)},log:function(e){GM_log(e)},getResourceText:function(e){return GM_getResourceText(e)},getResourceURL:function(e){return GM_getResourceURL(e)},registerMenuCommand:function(e,t,n){return GM_registerMenuCommand(e,t,n)},unregisterMenuCommand:function(e){GM_unregisterMenuCommand(e)},openInTab:function(e,t){GM_openInTab(e,t)},xmlHttpRequest:function(e){return GM_xmlhttpRequest(e)},download:function(e,t){return"string"==typeof e?GM_download(e,t):GM_download(e)},getTab:function(e){GM_getTab(e)},saveTab:function(e){GM_saveTab(e)},getTabs:function(e){GM_getTabs(e)},notification:function(e,t,n,o){"string"==typeof e?GM_notification(e,t,n,o):GM_notification(e,t)},setClipboard:function(e){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{type:"text",mimetype:"text/plain"};GM_setClipboard(e,t)},info:GM_info}},function(e,t,n){"use strict";n.r(t);var o,a=n(0),r=n(1);function s(){for(var e in a.a.itemsFromQueue)d(a.a.allDownloads[e])}function d(e){a.a.stoppedItems[e.fs_id]&&delete a.a.stoppedItems[e.fs_id];var t=document.querySelector('button[data-label="'.concat(e.fs_id,'"]'));if(a.a.downloadable){a.a.downloadingItems[e.fs_id]=e;var n=e.url,o=e.server_filename,r=0,d=void 0,l=document.querySelector('div[data-label="'.concat(e.fs_id,'"]')),c=l.parentElement,u=l.closest("tr").querySelector('td[data-label="speed"]');t.innerText="停止",e.request=GM_download({url:n,name:o,saveAs:!0,headers:{Host:"qdall01.baidupcs.com",Accept:"*/*","User-Agent":"netdisk;P2SP;2.2.60.26","Accept-Encoding":"identity","Accept-Language":"ja-JP","Accept-Charset":"*"},onprogress:function(e){d=e;var t=Math.round(100*d.loaded/d.total);c.className="progress-radial progress-".concat(t),l.innerText="".concat(t,"%")},onload:function(){e.progressLoader&&clearInterval(e.progressLoader),c.className="progress-radial progress-100",l.innerText="100%",u.innerText="",t.innerText="重新下载",a.a.completedItems[e.fs_id]=e,delete a.a.downloadingItems[e.fs_id],GM_notification({text:"下载完成",title:o,highlight:!0}),s()},onerror:function(){e.progressLoader&&clearInterval(e.progressLoader),c.className="progress-radial progress-0",l.innerHTML='<span style="color: red">error</span>',t.innerText="重新下载",u.innerText="",a.a.stoppedItems[e.fs_id]=e,delete a.a.downloadingItems[e.fs_id],s()}}),e.progressLoader=setInterval((function(){if(d){var e=d.loaded-r;r=d.loaded,u.innerText="".concat(i(e),"/秒")}}),1e3)}else t.innerText="等待中"}function i(e){var t=Math.round(e/1024);return t<=1e3?"".concat(t," KiB"):"".concat(Math.round(t/10.24)/100," MiB")}function l(e){return new Promise((function(t,n){GM_xmlhttpRequest({url:"http://pcs.baidu.com/rest/2.0/pcs/file?app_id=778750&ver=2.0&method=locatedownload&path="+encodeURIComponent(e.path),method:"GET",responseType:"json",headers:{"User-Agent":"netdisk;P2SP;2.2.60.26"},onload:function(o){if(o.response.hasOwnProperty("client_ip")){var r=o.response.urls[0].url+"&filename="+encodeURIComponent(e.server_filename);return e.url=r,function(e){document.getElementById("popup-tbody").insertAdjacentHTML("beforeend",'\n        <tr id="row-'.concat(e.fs_id,'">\n          <td data-label="filename">').concat(e.server_filename,'</td>\n          <td data-label="download">\n            <div class="wrap">\n              <div class="progress-radial progress-0">\n                <div data-label="').concat(e.fs_id,'" class="overlay">0%</div>\n              </div>\n            </div>\n          </td>\n          <td data-label="url">').concat(i(e.size),'</td>\n          <td data-label="speed"></td>\n          <td data-label="operation">\n            <button data-label="').concat(e.fs_id,'">等待中</button>\n            <svg id="delete-item-').concat(e.fs_id,'"\n                class="delete-item"\n                style="cursor: pointer; position: absolute; right: 5px"\n                xmlns="http://www.w3.org/2000/svg"\n                height="24" viewBox="0 0 24 24" width="24">\n                    <path d="M0 0h24v24H0z" fill="none"/>\n                    <path d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12z"/>\n            </svg>\n          </td>\n        </tr>\n  ')),document.querySelector('button[data-label="'.concat(e.fs_id,'"]')).addEventListener("click",(function(t){var n=a.a.downloadingItems[e.fs_id];if(n){if(confirm("停止后将需要重新下载, 确认吗?"))n.request.abort(),clearInterval(n.progressLoader),t.target.innerText="重新下载",a.a.stoppedItems[e.fs_id]=e,delete a.a.downloadingItems[e.fs_id],s();return!1}d(e)})),document.getElementById("delete-item-".concat(e.fs_id)).addEventListener("click",(function(){confirm("确认删除?")&&(e.request&&e.request.abort(),delete a.a.allDownloads[e.fs_id],delete a.a.downloadingItems[e.fs_id],delete a.a.completedItems[e.fs_id],delete a.a.stoppedItems[e.fs_id],document.getElementById("popup-tbody").removeChild(document.getElementById("row-".concat(e.fs_id))),s())}))}(e),t(e)}return n(o)}})}))}function c(){var e=document.querySelector(".modal-wrapper");e.className=e.className+" open"}function u(){document.querySelector(".modal-wrapper").className="modal-wrapper"}function _(){var e=a.a.selectedList,t=a.a.allDownloads,n=a.a.autoStart,o=[];e.forEach((function(e){void 0===t[e.fs_id]&&(t[e.fs_id]=e,o.push(l(e)))})),Promise.all(o).then((function(e){e.forEach((function(e){n&&d(e)}))}))}window.onunload=function(){r.a.setValue("downloadingItems",a.a.downloadingItems),r.a.setValue("stoppedItems",a.a.stoppedItems),r.a.setValue("completedItems",a.a.completedItems),a.a.stopAll()},o=GM_getResourceText("customStyle"),GM_addStyle(o),document.body.insertAdjacentHTML("beforeend",'\n        <div class="modal-wrapper">\n            <div class="modal-overlay"></div>\n            <div class="modal-window">\n                <div class="modal-content">\n\x3c!--                    <button id="copy-code" class="disable">复制到剪切板</button>--\x3e\n              <table>\n                <thead>\n                  <tr>\n                    <th scope="col">文件</th>\n                    <th scope="col">进度</th>\n                    <th scope="col">大小</th>\n                    <th scope="col">速度</th>\n                    <th scope="col">操作</th>\n                  </tr>\n                </thead>\n                <tbody id="popup-tbody"></tbody>\n              </table>\n                </div>\n\x3c!--                <span class="modal-close">×</a>--\x3e\n            </div>\n        </div>\n        <div id="container-floating">\n          <div class="nd1 nds" data-toggle="tooltip" data-placement="left" onclick="alert(\'此功能正在开发中...\')">\n              <img class="reminder" src="https://ssl.gstatic.com/bt/C3341AA7A1A076756462EE2E5CD71C11/1x/bt_compose2_1x.png">\n          </div>\n          <div id="floating-button" data-toggle="tooltip" data-placement="left" data-original-title="Create">\n            <p class="plus">+</p>\n            <img class="edit" src="//ssl.gstatic.com/bt/C3341AA7A1A076756462EE2E5CD71C11/1x/ic_reminders_speeddial_white_24dp.png">\n          </div>\n        </div>\n    '),document.querySelectorAll(".modal-overlay,.modal-close").forEach((function(e){return e.addEventListener("click",u)})),document.querySelector("#floating-button").addEventListener("click",c),_(),document.getElementById("floating-button").addEventListener("click",(function(){c(),_()}))}]);