filesafe/dist/js/misc/utils.js
Bobby Wibowo d666e278ec
Refactored "location" -> "window.location"
In client JS files, for readibility and consistency.

They'd work the same either way, but I'd think they'd be easier to
read and understand this way.
2020-05-26 02:39:28 +07:00

3 lines
1.9 KiB
JavaScript

lsKeys.siBytes="siBytes",page.prepareShareX=function(){var e=page.token?{token:page.token||"",albumid:page.album||""}:{};e.filelength=page.fileLength||"",e.age=page.uploadAge||"",e.striptags=page.stripTags||"";for(var t=[],a=Object.keys(e),n=0;n<a.length;n++)t.push(' "'+a[n]+'": "'+e[a[n]]+'"');var r=(window.location.hostname+window.location.pathname).replace(/\/(dashboard)?$/,""),o=r.replace(/\//g,"_"),i=document.querySelector("#ShareX"),s='{\n "Name": "'+o+'",\n "DestinationType": "ImageUploader, FileUploader",\n "RequestMethod": "POST",\n "RequestURL": "'+window.location.protocol+"//"+r+'/api/upload",\n "Headers": {\n'+t.join(",\n")+'\n },\n "Body": "MultipartFormData",\n "FileFormName": "files[]",\n "URL": "$json:files[0].url$",\n "ThumbnailURL": "$json:files[0].url$"\n}',l=new Blob([s],{type:"application/octet-binary"});i.setAttribute("href",URL.createObjectURL(l)),i.setAttribute("download",o+".sxcu")},page.getPrettyDate=function(e){return e.getFullYear()+"/"+(e.getMonth()<9?"0":"")+(e.getMonth()+1)+"/"+(e.getDate()<10?"0":"")+e.getDate()+" "+(e.getHours()<10?"0":"")+e.getHours()+":"+(e.getMinutes()<10?"0":"")+e.getMinutes()+":"+(e.getSeconds()<10?"0":"")+e.getSeconds()},page.getPrettyBytes=function(e){if("number"!=typeof e&&!isFinite(e))return e;var t="0"!==localStorage[lsKeys.siBytes],a=e<0?"-":"",n=t?1e3:1024;if(a&&(e=-e),e<n)return""+a+e+" B";var r=Math.min(Math.floor(Math.log(e)*Math.LOG10E/3),8);return""+a+Number((e/Math.pow(n,r)).toPrecision(3))+" "+((t?"kMGTPEZY":"KMGTPEZY").charAt(r-1)+(t?"":"i"))+"B"},page.escape=function(e){if(!e)return e;var t,a=String(e),n=/["'&<>]/.exec(a);if(!n)return a;var r="",o=0,i=0;for(o=n.index;o<a.length;o++){switch(a.charCodeAt(o)){case 34:t="&quot;";break;case 38:t="&amp;";break;case 39:t="&#39;";break;case 60:t="&lt;";break;case 62:t="&gt;";break;default:continue}i!==o&&(r+=a.substring(i,o)),i=o+1,r+=t}return i!==o?r+a.substring(i,o):r};
//# sourceMappingURL=utils.js.map