forked from heymind/OneDrive-Index-Cloudflare-Worker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
40 lines (32 loc) · 1.17 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
async function renderReadme() {
const resp = await fetch("readme.md")
if(!resp.ok) return
document.querySelector(".container").insertAdjacentHTML('beforeend','<div class="readme">'+window.marked(await resp.text()) + "</div>")
Prism.highlightAll()
}
function humanFileSize(bytes, si) {
bytes = parseInt(bytes,10)
var thresh = si ? 1000 : 1024;
if(Math.abs(bytes) < thresh) {
return bytes + ' B';
}
var units = si
? ['kB','MB','GB','TB','PB','EB','ZB','YB']
: ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB'];
var u = -1;
do {
bytes /= thresh;
++u;
} while(Math.abs(bytes) >= thresh && u < units.length - 1);
return bytes.toFixed(1)+' '+units[u];
}
document.addEventListener("DOMContentLoaded", function() {
document.querySelectorAll("a.item").forEach(function(i){
i.insertAdjacentHTML('beforeend',
'<div style="flex-grow:1"></div>'
+ ( i.hasAttribute("size") ? '<span class="size">'+humanFileSize(i.getAttribute("size"),true)+'</span>' : '')
)
})
});
import "https://cdn.jsdelivr.net/npm/marked/marked.min.js"
renderReadme().catch(console.error)