js/page/filesize.js

31 lines
550 B
JavaScript
Raw Normal View History

import {text, html} from '../skooma.js'
2022-06-09 13:11:02 +00:00
import element from "../element.js"
element(class FileSize extends HTMLElement {
static attributes = {file: true}
constructor() {
super()
this.attachShadow({mode: "open"})
}
connectedCallback() {
this.update()
}
fileChanged() {
this.update()
}
update() {
if (this.file) {
fetch(this.file)
.then(response=>response.arrayBuffer())
.then(buffer => buffer.byteLength)
.then(length => {
this.shadowRoot.replaceChildren(text`(${length} Bytes unminified)`)
})
}
}
})