'use strict';Registry.require("promise statistics helper xmlhttprequest uri convert tools".split(" "),function(){var x=rea.FEATURES,f=Registry.get("promise"),E,F,u=Registry.get("uri"),y=Registry.get("helper"),z=Registry.get("convert"),A=Registry.get("tools"),B=Registry.get("statistics"),G,L=A.createQueue(1),I=function(k){var b=f();z.blob2str(k,function(a,g){g?b.reject(g):b.resolve(a)});return b.promise()},q=function(f,b){var a=(f?f.split("/"):[]).concat(b?[b]:[]).join("/");return a?("/"==a.substr(0,
1)?"":"/")+a:""},M=function(f,b){b=new b(f);Object.keys(f).forEach(function(a){var g=Object.getOwnPropertyDescriptor(f,a);if(g.get){var n={get:g.get,enumerable:!0};g.set&&(n.set=g.set);Object.defineProperty(b,a,n)}else b[a]=b[a]||f[a]});Object.keys(b).forEach(function(a){var g=Object.getOwnPropertyDescriptor(b,a);g.get||g.set||(f[a]=f[a]||b[a])});f.config=b.config=y.assign(f.config||{},b.config||{});return b},C=function(k){var b={type:k,extend:function(a){return b=M(b,a)},request:function(a){var b=
function(){var b=f(),e=function(c){console.debug("rest service: request failed",c);b.reject(c)},g="xml"===a.responseType,p="headers"===a.responseType;(g||p)&&delete a.responseType;F(a,{onload:function(c){if(-1==[200,201,204,207].indexOf(c.status))e(c);else{if(g)if(a.anonymous||a.fetch){var d=new window.DOMParser;c.result=d.parseFromString(c.responseText,"text/xml")}else c.result=c.responseXML;else c.result=p?E.parseHeaders(c.responseHeaders):c.response;b.resolve(c)}},onerror:e,ontimeout:e,onprogress:b.notify},
{internal:!0});return b.promise()};return a.no_queue?b():L.add(b)},error:function(a){var b=a.status;try{b=b+" | "+a.responseText}catch(f){}B.tC(k,"error","request: "+b)},wait:function(a){return function(){return a.apply(this,arguments).then(function(a){return a},function(a){return f.Breach(a?a.responseText||a.statusText:null)})}}};return b},D=function(k){var b=k.type,a=[],g=null,n,e={config:{auth_prefix:"Bearer"},changes:function(){var a;return{listen:function(){a||(a=f(),e.watch&&e.watch.start());
return a.promise()},notify:function(c){a.notify(c)}}}(),request:function(a){a.no_auth||(a.headers=a.headers||{},a.headers.Authorization=e.config.auth_prefix+" "+e.credentials.access_token);return k.request(a)},oauth:function(){var a,c={run:function(){if(n)return n;var d=f(),h=n=d.promise();a="!!"+b+"-"+y.createUUID();var l=e.credentials?e.credentials.refresh_token:null,r=function(a,c){e.credentials=c;d.resolve();d=null;a&&a.close()};(function(){if(!e.config.refresh_supported||!l)return f.Pledge();
var a=f(),d=function(){l=null;delete e.credentials.refresh_token};F({url:c.getRefreshUrl(l),fetch:!x.RUNTIME.SAFARI},{onload:function(a){if(a=c.onUrl(a.finalUrl))a.error||!a.access_token?(B.tC(b,"error","auth refresh token: "+(a.error||"!access_token")),d()):r(null,a)},onerror:d,ondone:a.resolve});return a.promise()})().then(function(){if(d){if(!e.config.refresh_supported)return f.Pledge();var a=f(),m=G({url:c.getRefreshUrl()});m.promise.progress(function(a){var h;d&&(h=c.onUrl(a.url))&&(h.error||
!h.access_token?(B.tC(b,"error","auth refresh: "+(h.error||"!access_token")),e.config.refresh_supported=!1):r(m,h))}).always(a.resolve);return a.promise()}}).then(function(){if(d){var a=f(),m=G({url:c.getAuthUrl()});m.promise.progress(function(a){var h;d&&(h=c.onUrl(a.url))&&(h.error||!h.access_token?B.tC(b,"error","auth: "+(h.error||"!access_token")):r(m,h))}).always(a.resolve);return a.promise()}}).done(function(){n=null;d&&d.reject("auth_failed")});return h},getAuthUrl:function(){return e.config.request_uri+
"?"+u.hash2params({response_type:e.config.response_type,client_id:e.config.client_id,redirect_uri:e.config.redirect_uri,state:a,scope:e.config.scope})},getRefreshUrl:function(c){return e.config.redirect_uri+"?"+u.hash2params({client_id:e.config.client_id,redirect_uri:e.config.redirect_uri,state:a,scope:e.config.scope,refresh_token:c})},onUrl:function(c){var h,b;if(c&&0===c.indexOf(e.config.redirect_uri)&&(b=u.parse(c))&&(h=u.params2hash(b))&&(h.access_token||h.error)&&h.state===a)return{uid:h.uid,
access_token:h.access_token,refresh_token:h.refresh_token,error:h.error}}};return c}(),wait:function(b){return k.wait(function(){if(e.credentials.access_token)return b.apply(this,arguments);var c=arguments,d=f();a.push(function(){d.consume(b.apply(this,c))});e.oauth.run().done(function(){a.forEach(function(a){a()});a=[]}).fail(function(a){d.reject(a)});return d.promise()})}},w=x.HTML5.LOCALSTORAGE;Object.defineProperty(e,"credentials",{get:function(){if(null===g){B.tC(b,"init");if(w)try{var a=JSON.parse(w.getItem(e.config.storage_key));
g={uid:a.uid,access_token:a.access_token,refresh_token:a.refresh_token}}catch(c){}g=g||{}}return g},set:function(a){if(w)try{w.setItem(e.config.storage_key,JSON.stringify({uid:a.uid,access_token:a.access_token,refresh_token:a.refresh_token}))}catch(c){}g=a},enumerable:!0});return e},N=function(k){var b=k.type,a=null,g={config:{},changes:function(){var a;return{listen:function(){a||(a=f(),g.watch&&g.watch.start());return a.promise()},notify:function(b){a.notify(b)}}}(),request:function(a){if(!g.credentials.basic_auth)return f.Breach("Authentication failed");
a.no_auth||(a.headers=a.headers||{},a.headers.Authorization="Basic "+g.credentials.basic_auth);return k.request(a)},wait:function(a){return k.wait(function(){return a.apply(this,arguments)})}};Object.defineProperty(g,"credentials",{get:function(){null===a&&(B.tC(b,"init"),a={basic_auth:g.config.basic_auth});return a},set:function(b){a=b},enumerable:!0});return g},K=function(k){var b,a,g,n,e=null,w=null,p,c,d,h,l,r=function(a){var c;a&&(c=a.firstChild.nextSibling?a.firstChild.nextSibling:a.firstChild);
return c},v=function(a){return k.wait(function(){var c=arguments;return t.init().then(function(){return a.apply(this,c)})})},m=function(a,c){var b,d;if((b=a.getElementsByTagNameNS("*",c)[0])&&(d=b.firstChild))return d.nodeValue},J=function(c){var d=[];c=c.getElementsByTagNameNS("*","response");for(var h=0;h<c.length;h++){var r=c[h],e=m(r,"href"),e=e.replace(/\/$/,""),l=r.getElementsByTagNameNS("*","propstat")[0].getElementsByTagNameNS("*","prop")[0],r=m(l,"getlastmodified"),f=m(l,"getetag"),v=m(l,
"getcontentlength"),l=l.getElementsByTagNameNS("*","resourcetype")[0].getElementsByTagNameNS("*","collection")[0],e=e.replace(new RegExp("^("+[y.escapeForRegExpURL(a+b)+"/?",y.escapeForRegExpURL(g+b)+"/?"].join("|")+")"),"");l||(e={etag:f,name:e,modifiedTime:(new Date(r)).getTime(),size:0<=v?v:void 0,removed:-1==v},d.push(e))}return d},H=function(a,b){b=b||{};b.set_current_list&&(p={});return t.request({method:"PROPFIND",url:a,headers:{"Content-Type":"text/xml; charset=UTF-8",Depth:void 0!==b.depth?
b.depth:1},responseType:"xml"}).then(function(a){a=a.result;var d;if(null===a||!(d=r(a))||!d.childNodes)return f.Breach();a=J(d);b.set_current_list&&((d=m(d,"td:cursor"))&&(c=d),a.forEach(function(a){p[a.name]=a}));return a})},O=function(a,b){var d={"Content-Type":"text/xml; charset=UTF-8",Depth:1,Timeout:90};b&&(d.Cursor=b);return t.request({method:"SUBSCRIBE",url:a,headers:d,responseType:"xml",no_queue:!0}).then(function(a){a=a.result;var b;if(null===a)return f.Pledge({changes:[],cursor:c});if(!(b=
r(a))||!b.childNodes)return f.Breach();a=J(b);b=m(b,"td:cursor");return{changes:a,cursor:b}})},t={config:{watch_interval:36E5},request:function(a){a.headers=a.headers||{};a.headers["User-Agent"]="Tampermonkey";a.headers["X-Requested-With"]="XMLHttpRequest";a.headers.Cookie="";return k.request.apply(this,arguments).then(function(a){return a},function(c){if(!c||-1!=[403,500].indexOf(c.status))return a.backoff=2*(a.backoff||1E3),A.sleep(a.backoff).then(function(){return t.request(a)});if(404==c.status)return f.Pledge(c);
t.error(c);return f.Breach(c)})},init:function(){if(n)return n;b=q(t.config.root,t.config.path);a=t.config.url||"";"/"==a.slice(-1)&&(a=a.slice(0,-1));g=u.parse(a).pathname;"/"==g.slice(-1)&&(g=g.slice(0,-1));var c=f();n=c.promise();var d=a+b;t.request({method:"OPTIONS",url:a,responseType:"headers"}).done(function(a){a=a.result;var c;a&&(c=a["access-control-allow-methods"])&&-1!=c.indexOf("EDITOR")&&(l=!0)}).always(function(){H(d,{depth:0}).done(c.resolve).fail(function(){var d=[];f.onebyone(b.split("/").filter(function(a){return a}).map(function(c){d.push(c);
var b=d.join("/");return function(){return t.request({method:"MKCOL",url:a+"/"+b,headers:{"Content-Type":"text/xml; charset=UTF-8"},responseType:"xml"})}})).done(c.resolve).fail(c.reject)})});return n},list:v(function(c){return H(a+b,{set_current_list:!0}).then(function(a){var b={};return a.map(function(a){if(!c){if(b[a.name])return;b[a.name]=!0}return{name:a.name,size:a.size||0,id:a.id,etag:a.etag,md5:a.md5Checksum,modified:(new Date(a.modifiedTime)).getTime(),precision:1E3,removed:a.removed}}).filter(function(a){return a})})}),
get:v(function(c){return t.request({method:"GET",url:a+q(b,c.name||c),headers:{"Content-Type":"text/xml; charset=UTF-8"},responseType:"arraybuffer"}).then(function(a){return new Blob([a.result])})}),put:v(function(c,d,h){var m=c.name||c,r,l,f;c={"Content-Type":"application/octet-stream"};var v=null===w;h&&h.lastModified&&(r=h.lastModified,f=(new Date(h.lastModified)).toISOString(),l=h.lastModified/1E3,w||v)&&(c["X-OC-Mtime"]=l);return t.request({method:"PUT",url:a+q(b,m),headers:c,data_type:"typified",
data:{type:"raw",value:d},responseType:"headers"}).then(function(c){if((c=c.result)&&v){var d;w="accepted"==c["x-oc-mtime"]||c.date&&(d=(new Date(c.date)).getTime())&&(d==r||d==Math.floor(l))?!0:!1}if(!w&&!e&&f)return t.request({method:"PROPPATCH",url:a+q(b,m),headers:{"Content-Type":"text/xml; charset=UTF-8"},responseType:"xml",data:['<?xml version="1.0"?><d:propertyupdate xmlns:d="DAV:"><d:set><d:prop>',"<d:getlastmodified>"+f+"</d:getlastmodified>","</d:prop></d:set></d:propertyupdate>"].join("")}).then(function(a){a=
a.result;var c,b,d;a&&(c=a.childNodes[0])&&(b=c.getElementsByTagNameNS("*","status")[0])&&(d=b.firstChild.nodeValue)&&-1!=d.search(/HTTP\/[0-9\.]+ 403/)&&(console.warn("WebDAV: no way to set file modification date! This might cause redundant up and downloads."),e=!0)},function(){console.warn("WebDAV: no way to set file modification date! This might cause redundant up and downloads.");e=!0})})}),delete:v(function(c){return t.request({method:"DELETE",url:a+q(b,c.name||c),headers:{"Content-Type":"text/xml; charset=UTF-8"}})}),
watch:{start:function(){if(!d){d=!0;var m=null,r=function(){h=null;if(d)if(!1===m){var e=p;H(a+b,{set_current_list:!0}).then(function(){e&&(Object.keys(e).forEach(function(a){var c=p[a];a=e[a];c?a.modifiedTime!=c.modifiedTime&&k.changes.notify({time:c.modifiedTime,name:c.name}):k.changes.notify({time:Date.now(),name:a.name,removed:!0})}),Object.keys(p).forEach(function(a){e[a]||(a=p[a],k.changes.notify({time:a.modifiedTime,name:a.name}))}))}).fail(function(a){console.warn("WebDAV: file changes check failed",
a)}).always(function(){h=window.setTimeout(r,t.config.watch_interval)})}else{var l=100;O(a+b,c).then(function(a){var b=a.changes;c=a.cursor;l=1;b.forEach(function(a){k.changes.notify({time:a.modifiedTime,name:a.name,removed:a.removed})})},function(){if(null===m)m=!1;else return l*=2,A.sleep(l)}).always(r)}};v(function(){if(!d)return f.Breach();r();return f.Pledge()})()}},stop:function(){d=!1;h&&(window.clearTimeout(h),h=null)}},getRemoteUrl:function(c){if(l)return a+q(b,c)+"?method=editor#bypass=true"},
getRemoteDomains:function(){return[u.parse(a).origin.replace(/^.*:\/\//,"")]}};return t};Registry.register("cloud","6095",{init:function(f,b,a){G=f;E=Registry.get("xmlhttprequest",b,a);F=E.run},drive:function(){var k,b;(k=x.HTML5.LOCALSTORAGE)&&(b=k.getItem("dropbox_poll_interval"))||(b=18E5);return(new C("drive")).extend(D).extend(function(a){var g,n,e={config:{redirect_uri:"https://auth.tampermonkey.net/oauth.php",refresh_supported:!0,request_uri:"https://accounts.google.com/o/oauth2/v2/auth",
client_id:"408438522028-3cgn3t3jas3fak7isbnfod1q4h15g2fv.apps.googleusercontent.com",storage_key:"gd_config",scope:"https://www.googleapis.com/auth/drive.appdata",response_type:"token",watch_interval:b},request:function(b){return a.request.apply(this,arguments).then(function(a){return a},function(a){if(!a||-1!=[403,500].indexOf(a.status))return b.backoff=2*(b.backoff||1E3),A.sleep(b.backoff).then(function(){return e.request(b)});if(-1!=[400,401].indexOf(a.status)){if(console.warn("Google Drive: authentication error",
a),delete e.credentials.access_token,!b.retry_auth)return b.retry_auth=!0,e.oauth.run().then(function(){return e.request(b)})}else if(404==a.status)return f.Pledge(a);e.error(a);return f.Breach(a)})},list:a.wait(function(a){var b=[],c=f(),d=function(a){return"https://www.googleapis.com/drive/v3/files?"+u.hash2params({spaces:"appDataFolder",pageToken:a,orderBy:"modifiedTime desc",fields:"nextPageToken, files(id, size, name, modifiedTime, md5Checksum)",pageSize:500})},h=function(a){return e.request({method:"GET",
url:a,headers:{"Content-Type":"application/json"}}).then(function(a){a=(a=a.result)?JSON.parse(a):{files:[]};b=b.concat(a.files);if(a.nextPageToken)return h(d(a.nextPageToken));c.resolve(b)})};h(d());return c.promise().then(function(c){var b={};return c.map(function(c){if(!a){if(b[c.name])return;b[c.name]=!0}return{name:c.name,size:c.size||0,id:c.id,md5:c.md5Checksum,modified:(new Date(c.modifiedTime)).getTime()}}).filter(function(a){return a})})}),get:a.wait(function(a){return e.request({method:"GET",
url:"https://www.googleapis.com/drive/v3/files/"+(a.id||a)+"?"+u.hash2params({spaces:"appDataFolder",alt:"media"}),responseType:"arraybuffer"}).then(function(a){return new Blob([a.result])})}),put:a.wait(function(a,b,c){var d=a.name||a,h=a.id,l=y.createUUID();return f.Pledge().then(function(){if(b)return I(b)}).then(function(a){var b=c&&c.lastModified?(new Date(c.lastModified)).toISOString():void 0,m=[];m.push("--"+l);m.push("Content-Type: application/json");m.push("");m.push(JSON.stringify({name:d,
parents:h?void 0:["appDataFolder"],modifiedTime:b}));m.push("--"+l);a&&(m.push("Content-Type: application/octet-stream"),m.push("Content-Transfer-Encoding: base64"),m.push(""),m.push(z.Base64.encode(a)),m.push("--"+l+"--"));m.push("");return e.request({method:h||!a?"PATCH":"POST",url:"https://www.googleapis.com/"+(a?"upload/":"")+"drive/v3/files"+(h?"/"+h:"")+"?"+u.hash2params({uploadType:"multipart"}),headers:{"Content-Type":"multipart/related; boundary="+l},data:m.join("\r\n")})})}),delete:a.wait(function(a){return e.request({method:"DELETE",
url:"https://www.googleapis.com/drive/v3/files/"+(a.id||a)+"?"+u.hash2params({spaces:"appDataFolder"}),headers:{"Content-Type":" application/json"}})}),revoke:a.wait(function(){var b=e.credentials.access_token;return b?a.request({method:"GET",url:"https://accounts.google.com/o/oauth2/revoke?"+u.hash2params({token:b})}):f.Breach()}),compare:function(a,b){var c=f(),d;(d=a.md5)&&d==z.MD5(b,"utf-8")?c.resolve(!0):c.resolve(!1);return c.promise()},watch:{start:function(){if(!g){g=!0;var b,k=function(){n=
null;g&&e.request({method:"GET",url:"https://www.googleapis.com/drive/v3/changes/?"+u.hash2params({pageToken:b,spaces:"appDataFolder",pageSize:1E3,includeRemoved:!0}),headers:{"Content-Type":" application/json"}}).then(function(c){c=c.result;if(!g)return f.Breach();var d=c?JSON.parse(c):{};if(!(b=d.newStartPageToken))return console.warn("Google Drive: watch token error",c),e.watch.stop();d.nextPageToken&&console.warn("Google Drive: too much changes",c);(d.changes||[]).forEach(function(c){var b,d;
"file"===c.type&&(d=c.file)&&(b=Date.parse(c.time),isNaN(b)&&(b=Date.now()),a.changes.notify({id:d.id,time:b,name:d.name,removed:c.removed}))})}).fail(function(a){console.warn("Google Drive: file changes check failed",a)}).always(function(){n=window.setTimeout(k,e.config.watch_interval)})};a.wait(function(){return g?e.request({method:"GET",url:"https://www.googleapis.com/drive/v3/changes/startPageToken",headers:{"Content-Type":" application/json"}}).then(function(a){a=a.result;if(!(b=(a?JSON.parse(a):
{}).startPageToken))return console.warn("Google Drive: watch token error",a),e.watch.stop();k()}):f.Breach()})()}},stop:function(){g=!1;n&&(window.clearTimeout(n),n=null)}}};return e})},dropbox:function(k){var b=k.path||"",a,g;(a=x.HTML5.LOCALSTORAGE)&&(g=a.getItem("dropbox_poll_interval"))||(g=18E5);return(new C("dropbox")).extend(D).extend(function(a){var e,k,p,c,d=!0,h=function(a){var c=[],m=f(),e=function(a){return l.request({method:"POST",url:"https://api.dropboxapi.com/2/files/list_folder"+
(a?"/continue":""),headers:{"Content-Type":" application/json"},data:{path:a?void 0:q(b),cursor:a}}).then(function(a){a=(a=a.result)?JSON.parse(a):{entries:[]};c=c.concat(a.entries);if(a.has_more&&a.cursor)return e(a.cursor);m.resolve({list:c,cursor:a.cursor})}).fail(m.reject)};d?(d=!1,l.put(".version",new Blob([rea.extension.manifest.version])).then(function(){e(a)}).fail(m.reject)):e(a);return m.promise()},l={config:{redirect_uri:"https://auth.tampermonkey.net/oauth.php",request_uri:"https://www.dropbox.com/oauth2/authorize",
client_id:"gq3auc9yym0e21y",storage_key:"db_config",response_type:"token",watch_interval:g},request:function(c){return a.request.apply(this,arguments).then(function(a){return a},function(a){if(!a||-1!=[500,429].indexOf(a.status))return c.backoff=2*(c.backoff||1E3),A.sleep(c.backoff).then(function(){return l.request(c)});if(-1!=[401].indexOf(a.status)&&(console.warn("Dropbox: authentication error",a),delete l.credentials.access_token,!c.retry_auth))return c.retry_auth=!0,l.oauth.run().then(function(){return l.request(c)});
l.error(a);return f.Breach(a)})},list:a.wait(function(a){return h().then(function(b){var d={};c=b.cursor;return b.list.map(function(c){if(!a){if(d[c.name])return;d[c.name]=!0}return{name:c.name,size:c.size,dropbox_hash:c.content_hash,modified:(new Date(c.client_modified)).getTime(),precision:1E3}}).filter(function(a){return a})}).always(function(){p&&c&&(p(),p=null)})}),get:a.wait(function(a){return l.request({method:"POST",url:"https://content.dropboxapi.com/2/files/download",headers:{"Dropbox-API-Arg":JSON.stringify({path:q(b,
a.name||a)})},responseType:"arraybuffer"}).then(function(a){return new Blob([a.result])})}),put:a.wait(function(a,c,d){a=a.name||a;d=d&&d.lastModified?(new Date(d.lastModified)).toISOString().match(/[^:]*:[^:]*:[^:.a-zA_Z]*/)[0]+"Z":void 0;return l.request({method:"POST",url:"https://content.dropboxapi.com/2/files/upload",headers:{"Dropbox-API-Arg":JSON.stringify({path:q(b,a),client_modified:d,mode:"overwrite"}),"Content-Type":"application/octet-stream"},data_type:"typified",data:{type:"raw",value:c}})}),
delete:a.wait(function(a){return l.request({method:"POST",url:"https://api.dropboxapi.com/2/files/delete",headers:{"Content-Type":" application/json"},data:{path:q(b,a.name||a)}})}),compare:function(a,c){var b=f();if(window.crypto&&window.ArrayBuffer){for(var d=z.str2arrbuf(c,"utf-8"),e=[],h=d.byteLength,l=1,g=function(){if(0===--l){var c=new window.ArrayBuffer;e.forEach(function(a){var b=c,d=new Uint8Array(b.byteLength+a.byteLength);d.set(new Uint8Array(b),0);d.set(new Uint8Array(a),b.byteLength);
c=d.buffer});window.crypto.subtle.digest("SHA-256",c).then(function(c){c=Array.from(new Uint8Array(c)).map(function(a){return("00"+a.toString(16)).slice(-2)}).join("");b.resolve(c==a.dropbox_hash)})}},k=0,n=0;n<h;n+=4194304,k++)(function(a){e.push(null);l++;window.crypto.subtle.digest("SHA-256",d.slice(n,n+Math.min(4194304,h-n))).then(function(c){e[a]=c;g()},function(){console.warn("Dropbox: unable to calculate SHA-256 hashes");b.reject()})})(k);g()}else console.warn("Dropbox: unable to calculate SHA-256 hashes"),
b.reject();return b.promise()},watch:{start:function(){if(!e){e=!0;var b=0,d=function(){k=null;b=0;if(e){if(!c)return console.warn("Dropbox: watch token error",c),l.watch.stop();l.request({method:"POST",url:"https://notify.dropboxapi.com/2/files/list_folder/longpoll",headers:{"Content-Type":" application/json"},no_auth:!0,no_queue:!0,data:{cursor:c,timeout:180}}).then(function(a){var d=a.result;if(!e)return f.Breach();a=d?JSON.parse(d):{};a.backoff&&(b=1E3*a.backoff);return a.changes?A.sleep(6E4).then(function(){return h(c)}).then(function(a){return(c=
a.cursor)?a.list:(console.warn("Dropbox: watch token error",d),l.watch.stop())}):null}).then(function(c){c&&c.forEach(function(c){var b,d=c[".tag"];-1!=["file","deleted"].indexOf(d)&&(b=Date.parse(c.server_modified),a.changes.notify({id:c.id,time:b,name:c.name,removed:"deleted"==d}))})}).fail(function(a){console.warn("Dropbox: file changes check failed",a)}).always(function(){k=window.setTimeout(d,b+l.config.watch_interval)})}};a.wait(function(){if(!e)return f.Breach();c?d():p=d;return f.Pledge()})()}},
stop:function(){e=!1;k&&(window.clearTimeout(k),k=null)}},getRemoteDomains:function(){return["dropbox.com","dropboxapi.com"]}};return l})},onedrive:function(k){var b=k.path||"",a,g,n;(a=x.HTML5.LOCALSTORAGE)&&(g=a.getItem("onedrive_poll_interval"))||(g=18E5);return(new C("onedrive")).extend(D).extend(function(a){var k,p,c=function(a){var c=f(),e=[],g=function(f){return d.request({method:"GET",url:f||"https://api.onedrive.com/v1.0/drive/special/approot:"+q(b)+":/children",headers:{"Content-Type":" application/json"}}).then(function(b){b=
(b=b.result)?JSON.parse(b):{value:[]};e=e.concat(b.value.map(function(a){return{id:a.id,name:a.name,size:a.size,sha1:a.file&&a.file.hashes?a.file.hashes.sha1Hash:void 0,modified:(new Date((a.fileSystemInfo?a.fileSystemInfo.lastModifiedDateTime:null)||a.lastModifiedDateTime)).getTime()}}));if(b["@odata.nextLink"])return g(b["@odata.nextLink"]);a.set_current_list&&(n=e);c.resolve(e)})};g();return c.promise()},d={config:{redirect_uri:"https://auth.tampermonkey.net/oauth.php",request_uri:"https://login.live.com/oauth20_authorize.srf",
client_id:"000000004C1A3122",storage_key:"od_config",response_type:"token",scope:"onedrive.appfolder",watch_interval:g},getRemoteDomains:function(){return["onedrive.live.com"]},request:function(c){return a.request.apply(this,arguments).then(function(a){return a},function(a){if(!a)return console.warn("OneDrive: timeout"),f.Breach("Timeout");if(-1!=[401].indexOf(a.status)){if(console.warn("OneDrive: authentication error",a),delete d.credentials.access_token,!c.retry_auth)return c.retry_auth=!0,d.oauth.run().then(function(){return d.request(c)})}else if(404==
a.status)return f.Pledge(a);d.error(a);return f.Breach(a)})},list:a.wait(function(){return c({set_current_list:!0})}),get:a.wait(function(a){return d.request({method:"GET",url:"https://api.onedrive.com/v1.0/drive/special/approot:"+q(b,encodeURIComponent(a.name||a))+":/content",responseType:"arraybuffer"}).then(function(a){return new Blob([a.result])})}),put:a.wait(function(a,c,e){a=encodeURIComponent((a.name||a).replace(/[#%<>:"|\?\*\/\\]/g,"-"));return d.request({method:"PUT",url:"https://api.onedrive.com/v1.0/drive/special/approot:"+
q(b,a)+":/content",headers:{"Content-Type":"application/octet-stream"},data_type:"typified",data:{type:"raw",value:c}}).then(function(a){var c=e&&e.lastModified?(new Date(e.lastModified)).toISOString():void 0;if(!c)return a;a=JSON.parse(a.result);return d.request({method:"PATCH",url:"https://api.onedrive.com/v1.0/drive/items/"+a.id,headers:{"Content-Type":"application/json"},data:JSON.stringify({fileSystemInfo:{lastModifiedDateTime:c}})})})}),delete:a.wait(function(a){return d.request({method:"DELETE",
url:"https://api.onedrive.com/v1.0/drive/special/approot:"+q(b,encodeURIComponent(a.name||a))})}),watch:{start:function(){if(!k){k=!0;var b=function(){p=null;if(k){var f=n;c({set_current_list:!0}).then(function(){if(f){var c={},b={};n.forEach(function(a){c[a.id]=a});f.forEach(function(a){b[a.id]=a});Object.keys(b).forEach(function(d){var f=c[d];d=b[d];f?d.modified!=f.modified&&a.changes.notify({time:f.modified,name:f.name}):a.changes.notify({time:Date.now(),name:d.name,removed:!0})});Object.keys(c).forEach(function(d){b[d]||
(d=c[d],a.changes.notify({time:d.modified,name:d.name}))})}}).fail(function(a){console.warn("OneDrive: file changes check failed",a)}).always(function(){p=window.setTimeout(b,d.config.watch_interval)})}};d.wait(function(){if(!k)return f.Breach();b();return f.Pledge()})()}},stop:function(){k=!1;p&&(window.clearTimeout(p),p=null)}}};return d})},yandex:function(k){var b,a;(b=x.HTML5.LOCALSTORAGE)&&(a=b.getItem("yandex_poll_interval"))||(a=18E5);return(new C("yandex")).extend(D).extend(K).extend(function(b){var n=
b.request;b.request=function(a){return function(){if(window.forge_sha256&&"PUT"==a.method&&a.data&&"raw"==a.data.type&&a.data.value){var b=f();I(a.data.value).then(function(b){a.headers.Etag=z.MD5(b);a.headers.Sha256=window.forge_sha256(b)}).always(b.resolve);return b.promise()}return f.Pledge()}().then(function(){return n(a).then(function(a){return a},function(b){return b&&-1!=[401].indexOf(b.status)&&(console.warn("Yandex: authentication error",b),delete p.credentials.access_token,!a.retry_auth)?
(a.retry_auth=!0,p.oauth.run().then(function(){return n(a)})):b})})};var e=b.init,q;b.init=function(){if(q)return q;var a=f();q=a.promise();p.request({method:"GET",url:"https://cloud-api.yandex.net/v1/disk/"}).done(function(a){a=(a=a.result)?JSON.parse(a):{};a.total_space&&a.used_space&&(a.used_space+5E7>a.total_space?console.warn("Yandex: low disk space warning, only "+(a.total_space-a.used_space)+" bytes available"):console.debug("Yandex: "+(a.total_space-a.used_space)+" bytes on disk available!"))}).always(function(){a.consume(e())});
return q};var p={config:y.assign({root:"/Programs/Tampermonkey",url:"https://webdav.yandex.ru",redirect_uri:"https://auth.tampermonkey.net/oauth.php",refresh_supported:!0,request_uri:"https://oauth.yandex.com/authorize",client_id:"a591fcd2ccd248f0baa84222898065f4",storage_key:"ya_config",response_type:"token",auth_prefix:"OAuth",watch_interval:a},k),getRemoteDomains:function(){return["disk.yandex.com"]},list:function(a){return b.list(a).then(function(a){return a.map(function(a){a.md5=a.etag;return a})})},
compare:function(a,b){var e=f(),g;(g=a.md5)&&g==z.MD5(b,"utf-8")?e.resolve(!0):e.resolve(!1);return e.promise()}};return p})},webdav:function(f){var b,a;(b=x.HTML5.LOCALSTORAGE)&&(a=b.getItem("webdav_poll_interval"))||(a=18E5);return(new C("webdav")).extend(N).extend(K).extend(function(){return{config:y.assign({root:"Tampermonkey",watch_interval:a},f)}})}})});
