// ==UserScript== // @name OneDrive 文件下载直链 // @namespace http://tampermonkey.net/ // @version 1.2.0 // @description 获得 OneDrive 文件下载直链的 TamperMonkey 插件 // @author KAAAsS // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @match https://*.sharepoint.com/personal/* // @grant GM_cookie // @grant GM_setClipboard // @grant GM_setValue // @grant GM_getValue // @grant GM_xmlhttpRequest // @require https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.min.js // @require https://unpkg.com/element-ui@2.14.1/lib/index.js // @connect * // @downloadURL none // ==/UserScript== !function(e){var t={};function n(i){if(t[i])return t[i].exports;var o=t[i]={i:i,l:!1,exports:{}};return e[i].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,i){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:i})},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 i=Object.create(null);if(n.r(i),Object.defineProperty(i,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(i,o,function(t){return e[t]}.bind(null,o));return i},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=9)}([function(e,t,n){"use strict";var i,o=function(){return void 0===i&&(i=Boolean(window&&document&&document.all&&!window.atob)),i},a=function(){var e={};return function(t){if(void 0===e[t]){var n=document.querySelector(t);if(window.HTMLIFrameElement&&n instanceof window.HTMLIFrameElement)try{n=n.contentDocument.head}catch(e){n=null}e[t]=n}return e[t]}}(),r=[];function s(e){for(var t=-1,n=0;n({AppName:"OneDrive 文件下载直链",AppVersion:"1.2.0"})},c=n(0),d=n.n(c),u=n(3),p={insert:"head",singleton:!1};d()(u.a,p),u.a.locals;function f(e,t,n,i,o,a,r,s){var l,c="function"==typeof e?e.options:e;if(t&&(c.render=t,c.staticRenderFns=n,c._compiled=!0),i&&(c.functional=!0),a&&(c._scopeId="data-v-"+a),r?(l=function(e){(e=e||this.$vnode&&this.$vnode.ssrContext||this.parent&&this.parent.$vnode&&this.parent.$vnode.ssrContext)||"undefined"==typeof __VUE_SSR_CONTEXT__||(e=__VUE_SSR_CONTEXT__),o&&o.call(this,e),e&&e._registeredComponents&&e._registeredComponents.add(r)},c._ssrRegister=l):o&&(l=s?function(){o.call(this,(c.functional?this.parent:this).$root.$options.shadowRoot)}:o),l)if(c.functional){c._injectStyles=l;var d=c.render;c.render=function(e,t){return l.call(t),d(e,t)}}else{var u=c.beforeCreate;c.beforeCreate=u?[].concat(u,l):[l]}return{exports:e,options:c}}var h=f(l,s,[],!1,null,"61dd7a3d",null);h.options.__file="src/components/Header.vue";var m=h.exports,v=function(){var e=this.$createElement,t=this._self._c||e;return t("svg",{staticClass:"icon",attrs:{t:"1589962875590",viewBox:"0 0 1024 1024",version:"1.1",xmlns:"http://www.w3.org/2000/svg","p-id":"2601"}},[t("path",{attrs:{d:"M730.020653 1018.946715l91.277028-89.978692a16.760351 16.760351 0 0 0 5.114661-11.803064 15.343983 15.343983 0 0 0-5.114661-11.803064l-400.123871-393.435467L821.691117 118.254899a17.075099 17.075099 0 0 0 0-23.606129L730.020653 4.670079a17.232473 17.232473 0 0 0-23.999564 0L202.030255 500.08402a16.445603 16.445603 0 0 0-4.721226 11.803064 15.265296 15.265296 0 0 0 5.114661 11.803064l503.597399 495.413941a17.153786 17.153786 0 0 0 23.999564 0z m0 0",fill:"#FFFFFF","p-id":"2602"}})])};v._withStripped=!0;var g=f({name:"ArrowIcon"},v,[],!1,null,"41f57a04",null);g.options.__file="src/icons/ArrowIcon.vue";var b=g.exports,_=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("div",{staticClass:"app-container"},[n("el-scrollbar",[n("div",{staticClass:"sub-container"},[n("div",{staticClass:"btn-group-files"},[""!==this.cookie?n("el-button",{attrs:{type:"primary",size:"mini"},on:{click:function(t){return e.handleIdm()}}},[e._v("IDM 下载\n ")]):e._e(),e._v(" "),""!==this.cookie?n("el-button",{attrs:{type:"primary",size:"mini"},on:{click:function(t){return e.handleAria()}}},[e._v("Aria 下载\n ")]):e._e(),e._v(" "),n("el-button",{attrs:{size:"mini"},on:{click:function(t){return e.handleCopyFile()}}},[e._v("复制链接")]),e._v(" "),n("el-tooltip",{staticClass:"item",attrs:{effect:"dark",content:"不太好用,建议优先使用 IDM 或 Aria 推送",placement:"top-start"}},[n("el-button",{attrs:{size:"mini"},on:{click:function(t){return e.handleBatchDownload()}}},[e._v("批量下载")])],1)],1),e._v(" "),n("el-table",{ref:"filesTable",staticStyle:{width:"100%"},attrs:{data:e.fileList,"tooltip-effect":"dark"},on:{"selection-change":e.handleSelectionChange}},[n("el-table-column",{attrs:{type:"selection",width:"55"}}),e._v(" "),n("el-table-column",{attrs:{prop:"filename",label:"文件名"}}),e._v(" "),n("el-table-column",{attrs:{label:"操作"},scopedSlots:e._u([{key:"default",fn:function(t){return[n("el-button",{attrs:{type:"primary",size:"mini"},on:{click:function(n){return e.handleDownload(t.row.directLink)}}},[e._v("下载\n ")]),e._v(" "),n("el-button",{attrs:{size:"mini"},on:{click:function(n){return e.handleCopyLink(t.row.directLink)}}},[e._v("复制链接\n ")])]}}])})],1)],1),e._v(" "),n("div",{staticClass:"sub-container"},[n("h3",{staticClass:"sub-title"},[e._v("Cookie 信息")]),e._v(" "),""===this.cookie?n("div",{staticClass:"not-tampermonkey-beta"},[n("el-alert",{attrs:{title:"无法获得 Cookie 信息",type:"info",description:"由于您没有使用 Tampermonkey Beta,因此无法自动获得 Cookie。请在“开发者选项-Application-Cookie”中,\n 复制 FedAuth 对应的值。然后在 AriaNG 的“自定义请求头”填写:Cookie: FedAuth=复制的值","show-icon":"",closable:!1}})],1):e._e(),e._v(" "),""!==this.cookie?n("div",{staticClass:"tampermonkey-beta"},[n("el-alert",{staticStyle:{"margin-bottom":"15px"},attrs:{title:"Cookie 信息",type:"success",description:"下载时在 AriaNG 的“自定义请求头”填写","show-icon":"",closable:!1}}),e._v(" "),n("el-input",{attrs:{type:"textarea",rows:3,placeholder:"Cookie"},model:{value:e.cookie,callback:function(t){e.cookie=t},expression:"cookie"}}),e._v(" "),n("div",{staticClass:"btn-group-files"},[n("el-button",{attrs:{type:"primary"},on:{click:function(t){return e.handleCopyCookie()}}},[e._v("复制")])],1)],1):e._e()]),e._v(" "),n("div",{staticClass:"sub-container"},[n("h3",{staticClass:"sub-title"},[e._v("设置")]),e._v(" "),n("div",{staticClass:"btn-group-files"},[n("el-button",{on:{click:function(t){return e.handleConfigAria()}}},[e._v("配置 Aria RPC")])],1)]),e._v(" "),n("div",{staticClass:"blank"})])],1)};_._withStripped=!0;let C={getFileList:async()=>{let e=[],t=document.location,n=t.host,i=new URLSearchParams(t.search).get("id"),o=await fetch(`https://${n}${i}`,{method:"PROPFIND",credentials:"include"});if(o.ok){let t=await o.text(),n=(new DOMParser).parseFromString(t,"text/xml").getElementsByTagName("D:response");for(const t of n){let n=t.getElementsByTagName("D:isFolder");if(n.length>=1&&"t"===n[0].textContent)continue;let i=t.getElementsByTagName("D:href"),o="";i.length>=1&&(o=encodeURI(decodeURI(i[0].textContent)));let a=t.getElementsByTagName("D:displayname"),r="";a.length>=1&&(r=a[0].textContent),e.push({filename:r,directLink:o})}}else{if(404!==o.status)throw new Error("无法解析OneDrive文件列表: "+o.status);let t=encodeURI(`https://${n}${i}`),a=i.split("/"),r=a[a.length-1];e.push({filename:r,directLink:t})}return e},getCookie:()=>new Promise((function(e,t){GM_cookie.list({name:"FedAuth"},(n,i)=>{if(i)return void t(i);let o=n[0].value;e("Cookie: FedAuth="+o)})})),setClipboard:e=>new Promise((function(t){GM_setClipboard(e,"text"),t(!0)})),getAriaConfig:()=>{let e=GM_getValue("aria_conf","null");return JSON.parse(e)},setAriaConfig:e=>{GM_setValue("aria_conf",JSON.stringify(e))}};const y=C.getFileList,k=C.getCookie,x=C.setClipboard,w=C.getAriaConfig,A=C.setAriaConfig;var S=function(){var e=this,t=e.$createElement,n=e._self._c||t;return n("el-dialog",{attrs:{title:"配置 Aria RPC",visible:e.visible},on:{"update:visible":function(t){e.visible=t}}},[n("el-form",{attrs:{model:e.form}},[n("el-form-item",{attrs:{label:"Aria RPC 地址"}},[n("el-input",{attrs:{autocomplete:"off"},model:{value:e.form.apiBase,callback:function(t){e.$set(e.form,"apiBase",t)},expression:"form.apiBase"}})],1),e._v(" "),n("el-form-item",{attrs:{label:"Aria RPC Token"}},[n("el-input",{attrs:{autocomplete:"off"},model:{value:e.form.token,callback:function(t){e.$set(e.form,"token",t)},expression:"form.token"}})],1),e._v(" "),n("el-form-item",{attrs:{label:"下载位置"}},[n("el-input",{attrs:{autocomplete:"off"},model:{value:e.form.downloadPath,callback:function(t){e.$set(e.form,"downloadPath",t)},expression:"form.downloadPath"}})],1)],1),e._v(" "),n("div",{staticClass:"dialog-footer",attrs:{slot:"footer"},slot:"footer"},[n("el-button",{on:{click:function(t){e.visible=!1}}},[e._v("取 消")]),e._v(" "),n("el-button",{attrs:{type:"primary"},on:{click:function(t){return e.handleConfirm()}}},[e._v("确 定")])],1)],1)};S._withStripped=!0;var P=f({name:"AriaConfigDialog",data:()=>({visible:!1,form:{apiBase:"",token:"",downloadPath:""}}),mounted(){let e=w();null!=e&&(this.form=e)},methods:{open(){this.visible=!0},handleConfirm(){this.visible=!1,A(this.form),this.$message.success("设置成功!")}}},S,[],!1,null,"93e08cfa",null);P.options.__file="src/components/AriaConfigDialog.vue";var $=P.exports,D={name:"PluginPanel",components:{AriaConfigDialog:$},data:()=>({fileList:null,cookie:null,multipleSelection:[]}),mounted(){this.loadFileList(),this.loadCookie()},methods:{loadFileList(){y().then(e=>{this.fileList=e,this.$nextTick(()=>{this.$refs.filesTable.clearSelection(),this.$refs.filesTable.toggleAllSelection()})}).catch(e=>{console.log("无法读取文件列表",e),this.$message.error("读取文件列表失败!"+e)})},loadCookie(){k().then(e=>{this.cookie=e}).catch(e=>{console.log("无法读取 Cookie",e),this.cookie=""})},getSelectedLinks(){return this.multipleSelection.map(e=>e.directLink)},handleSelectionChange(e){this.multipleSelection=e},handleCopyFile(){let e=this.getSelectedLinks();e.length<1?this.$message.error("请选择要下载的文件!"):x(e.join("\n")).then(()=>{this.$message.success("复制成功!")})},handleCopyCookie(){x(this.cookie).then(()=>{this.$message.success("复制成功!")})},handleDownload(e){window.open(e,"_blank")},handleCopyLink(e){x(e).then(()=>{this.$message.success("复制成功!")})},handleBatchDownload(){let e=this.getSelectedLinks();e.length<1?this.$message.error("请选择要下载的文件!"):e.forEach(e=>window.open(e,"_blank"))},handleIdm(){var e,t;((e,t)=>{let n=document.createElement("a");n.download=t,n.style.display="none";let i=new Blob([e]);n.href=URL.createObjectURL(i),document.body.appendChild(n),n.click(),document.body.removeChild(n)})((e=this.getSelectedLinks(),t=this.cookie,e.map(e=>`<\r\n${e}\r\n${t}\r\n>`).join("\r\n")+"\r\n\r\n"),"download.ef2"),this.$message.success("成功!请在 IDM 中导入此文件下载")},handleAria(){(async(e,t)=>{const n=w();if(!n)return"no_config";let i={header:[t]};n.downloadPath.length>0&&(i.dir=n.downloadPath);return Promise.all(e.map(async e=>{let t={jsonrpc:"2.0",method:"aria2.addUri",id:"sharepoint-list-plugin",params:["token:"+n.token,[e],i]};return console.log("发送 Aria RPC:",n.apiBase,JSON.stringify(t)),await new Promise((function(e,i){GM_xmlhttpRequest({method:"POST",responseType:"json",url:n.apiBase,data:JSON.stringify(t),timeout:3e3,onload(t){200===t.status?t.response.result?e(t.response):i("下载错误!"+t.response.message):(i("创建任务失败!"+t.responseText),console.error("创建任务失败!",t))},ontimeout(e){i("连接超时!"),console.error("连接超时!",e)},onerror(e){i("无法发送 Aria 下载请求!请尝试添加服务器路径到用户域名白名单。"),console.error("无法发送 Aria 下载请求!",e)}})}))}))})(this.getSelectedLinks(),this.cookie).then(e=>{if("no_config"===e)return this.$message.warning("还没配置过 Aria RPC,请先配置!"),void this.$emit("onOpenAriaDialog");this.$message.success("成功推送至 Aria!")}).catch(e=>{this.$message.error("推送失败!"+e)})},handleConfigAria(){this.$emit("onOpenAriaDialog")}}},L=n(4),O={insert:"head",singleton:!1},T=(d()(L.a,O),L.a.locals,f(D,_,[],!1,null,"62c87fde",null));T.options.__file="src/components/PluginPanel.vue";var E={name:"PluginDrawer",components:{AriaConfigDialog:$,PluginPanel:T.exports,ArrowIcon:b,Header:m},data:()=>({isHide:!0}),methods:{hide(){this.isHide=!this.isHide},handleOpenAriaDialog(){this.$refs.ariaDialog.open()}}},N=n(5),F={insert:"head",singleton:!1},M=(d()(N.a,F),N.a.locals,f(E,r,[],!1,null,"593a5798",null));M.options.__file="src/components/PluginDrawer.vue";var R={name:"app",components:{PluginDrawer:M.exports},data:()=>({AppName:"OneDrive 文件下载直链",AppVersion:"1.2.0"})},j=n(6),B={insert:"head",singleton:!1},I=(d()(j.a,B),j.a.locals,f(R,a,[],!1,null,"5ef48958",null));I.options.__file="src/app.vue";var z=I.exports,U=n(7),H={insert:"head",singleton:!1};d()(U.a,H),U.a.locals;(e=>{const t=document.getElementsByTagName("head")[0],n=document.createElement("link");n.rel="stylesheet",n.type="text/css",n.href=e,n.media="all",t.appendChild(n)})("https://unpkg.com/element-ui@2.14.1/lib/theme-chalk/index.css");const V="app_vue_"+Date.now(),G=document.createElement("div");G.id=V,document.body.appendChild(G),new o.a({el:"#"+V,render:e=>e(z)})}]);