This commit is contained in:
Drath
2023-06-28 20:16:39 +02:00
commit 7eeb201f1f
26 changed files with 627 additions and 0 deletions

View File

@@ -0,0 +1,40 @@
function addItem(url) {
getFileSize(url, insertRow);
}
async function getFileSize(url, myCallback) {
// needs proper cors config
var http = new XMLHttpRequest();
http.open('HEAD', url, true); // true = Asynchronous
http.onreadystatechange = function() {
if (this.readyState == this.DONE) {
if (this.status === 200) {
myCallback(url,parseInt(this.getResponseHeader('content-length')));
}
}
};
http.send();
}
function insertRow(url, size) {
let table = document.getElementById("table");
var newRow = table.insertRow(table.length);
let suffixes = ["B", "KB", "MB", "GB", "TB"];
var sindex = 0;
while(size > 1024) {
sindex+=1;
size/=1024;
}
newRow.insertCell(0).innerHTML = "<a href="+url+" download>"+url.split("/").pop()+"</a>";
newRow.insertCell(1).innerHTML = pRound(size) + " " + suffixes[sindex];
}
function pRound(num) {
// pretty round
mult = Math.ceil(Math.pow(10,3-String(num).split(".",1)[0].length));
return Math.round(num*mult)/mult;
}
// thoughts and prayers for everyone working in javascript