// ==UserScript== // @name OneDrive 文件下载直链 // @namespace http://tampermonkey.net/ // @version 1.0.0 // @description 获得 OneDrive 文件下载直链的 TamperMonkey 插件 // @author KAAAsS // @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw== // @match https://*.sharepoint.com/personal/* // @grant GM_cookie // @grant GM_setClipboard // @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 // @require https://cdn.bootcdn.net/ajax/libs/axios/0.21.0/axios.min.js // @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.0.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 v=h.exports,m=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"}})])};m._withStripped=!0;var g=f({name:"ArrowIcon"},m,[],!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"},[n("el-button",{attrs:{type:"primary"},on:{click:function(t){return e.handleCopyFile()}}},[e._v("复制所选链接")]),e._v(" "),n("el-button",{on:{click:function(t){return e.toggleSelection()}}},[e._v("取消选择")])],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:"blank"})])],1)};_._withStripped=!0;let x={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=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)}))};const y=x.getFileList,C=x.getCookie,w=x.setClipboard;var k={name:"PluginPanel",data:()=>({fileList:null,cookie:null,multipleSelection:[]}),mounted:function(){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(){C().then(e=>{this.cookie=e}).catch(e=>{console.log("无法读取 Cookie",e),this.cookie=""})},toggleSelection(e){e?e.forEach(e=>{this.$refs.filesTable.toggleRowSelection(e)}):this.$refs.filesTable.clearSelection()},handleSelectionChange(e){this.multipleSelection=e},handleCopyFile(){let e=this.multipleSelection.map(e=>e.directLink);e.length<1?this.$message.error("请选择要下载的文件!"):w(e.join("\n")).then(()=>{this.$message.success("复制成功!")})},handleCopyCookie(){w(this.cookie).then(()=>{this.$message.success("复制成功!")})},handleDownload(e){window.open(e,"_blank")},handleCopyLink(e){w(e).then(()=>{this.$message.success("复制成功!")})}}},S=n(4),T={insert:"head",singleton:!1},$=(d()(S.a,T),S.a.locals,f(k,_,[],!1,null,"62c87fde",null));$.options.__file="src/components/PluginPanel.vue";var E={name:"PluginDrawer",components:{PluginPanel:$.exports,ArrowIcon:b,Header:v},data:()=>({isHide:!0}),methods:{hide(){this.isHide=!this.isHide}}},P=n(5),A={insert:"head",singleton:!1},F=(d()(P.a,A),P.a.locals,f(E,r,[],!1,null,"593a5798",null));F.options.__file="src/components/PluginDrawer.vue";var L={name:"app",components:{PluginDrawer:F.exports},data:()=>({AppName:"OneDrive 文件下载直链",AppVersion:"1.0.0"})},N=n(6),D={insert:"head",singleton:!1},O=(d()(N.a,D),N.a.locals,f(L,a,[],!1,null,"5ef48958",null));O.options.__file="src/app.vue";var j=O.exports;var M=n(7),R={insert:"head",singleton:!1};d()(M.a,R),M.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 B="app_vue_"+Date.now(),H=document.createElement("div");H.id=B,document.body.appendChild(H),new o.a({el:"#"+B,render:e=>e(j)})}]);