webdav

坚果云

Stan na 02-04-2023. Zobacz najnowsza wersja.

Ten skrypt nie powinien być instalowany bezpośrednio. Jest to biblioteka dla innych skyptów do włączenia dyrektywą meta // @require https://update.greasyfork.org/scripts/463081/1169718/webdav.js

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

class webdav{constructor(a,b){this.Account=a,this.Password=b}NewFolder(a){let b={authorization:`Basic ${btoa(this.Account+":"+this.Password)}`};return new Promise((c,d)=>{GM_xmlhttpRequest({method:"MKCOL",timeout:3e3,headers:b,url:`https://dav.jianguoyun.com/dav/${a}/`,onload:c,onerror:d,ontimeout:d})})}UploadFiles(a,b,c,d){let e={authorization:`Basic ${btoa(this.Account+":"+this.Password)}`};return new Promise((f,g)=>{GM_xmlhttpRequest({method:"PUT",timeout:3e3,data:c,headers:e,url:`https://dav.jianguoyun.com/dav/${a}/${b}`,dataType:d,onload:function(a){201==a.status||204==a.status?f(!0):(console.error(a),f(!1))},onerror:g,ontimeout:g})})}DownloadFile(a,b){let c={authorization:`Basic ${btoa(this.Account+":"+this.Password)}`};return new Promise((d,e)=>{GM_xmlhttpRequest({method:"GET",timeout:3e3,headers:c,url:`https://dav.jianguoyun.com/dav/${a}/${b}`,onload:function(a){200==a.status?d(a.responseText):(console.error(a),d(!1))},onerror:e,ontimeout:e})})}GetAllFile(a,b){return new Promise((c,d)=>{GM_xmlhttpRequest({method:"PROPFIND",url:"https://dav.jianguoyun.com/dav/"+a,headers:{Authorization:`Basic ${btoa(this.Account+":"+this.Password)}`,Depth:b},onload:function(a){if(207==a.status){for(var b=new DOMParser,e=b.parseFromString(a.responseText,"text/xml"),f=e.getElementsByTagNameNS("DAV:","response"),g=[],h=0;h<f.length;h++){var j=f[h].getElementsByTagNameNS("DAV:","href")[0].textContent,k=f[h].getElementsByTagNameNS("DAV:","propstat")[0],l=k.getElementsByTagNameNS("DAV:","status")[0].textContent;if(l.includes("200 OK")){var m=k.getElementsByTagNameNS("DAV:","resourcetype")[0];0<m.getElementsByTagNameNS("DAV:","collection").length&&(j+="/"),g.push(j)}}c(g)}else console.error(a),d(new Error("The request failed with status code "+a.status))}})})}ExistsFile(a){return new Promise((b,c)=>{console.log(this),GM_xmlhttpRequest({method:"HEAD",url:"https://dav.jianguoyun.com/dav/"+a,headers:{Authorization:`Basic ${btoa(this.Account+":"+this.Password)}`},onload:function(a){var d=a.status;200==d?b(!0):404==d?b(!1):403==d?(b(!1),c("\u6743\u9650\u4E0D\u8DB3,\u62D2\u7EDD\u8BBF\u95EE")):c("The status code is "+d+" and the status text is "+a.statusText)}})})}}function AutoUploadFiles(a,b,c,d,e){return e||(e={},GM_listValues().forEach(function(a){e[a]=GM_getValue(a)})),new Promise(f=>{console.log("\u4E0A\u4F20\u6570\u636E",e);let g=GM_getValue("LBackupTimestamp",0),h=Date.now();if(86400000<h-g){let g=new webdav(a,b);g.ExistsFile(c).then(async a=>{a||(await g.NewFolder(c)),f(await g.UploadFiles(c,d,e,"json")),GM_setValue("LBackupTimestamp",h)})}else console.log("\u5907\u4EFD\u95F4\u9694\u9700\u8981\u5927\u4E8E24\u5C0F\u65F6")})}