mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 16:36:21 +00:00
52d336cc45
No more enforced curly for if/else/for/while/do blocks w/ one statement. With that said, auto-fixed all JS files to follow the rule. I'd also like to apologize for the inconveniences this commit cause, after all it was me who intentionally enforced curly rule back then. Why the change of heart? After doing some more non-JS codes recently, I realized it was pretty stupid of me to enforce that.
34 lines
936 B
JavaScript
34 lines
936 B
JavaScript
/* global LazyLoad */
|
|
|
|
const page = {
|
|
lazyLoad: null,
|
|
|
|
// byte units for getPrettyBytes()
|
|
byteUnits: ['B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB']
|
|
}
|
|
|
|
page.getPrettyBytes = num => {
|
|
// MIT License
|
|
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
|
|
if (!Number.isFinite(num)) return num
|
|
|
|
const neg = num < 0
|
|
if (neg) num = -num
|
|
if (num < 1) return (neg ? '-' : '') + num + ' B'
|
|
|
|
const exponent = Math.min(Math.floor(Math.log10(num) / 3), page.byteUnits.length - 1)
|
|
const numStr = Number((num / Math.pow(1000, exponent)).toPrecision(3))
|
|
const unit = page.byteUnits[exponent]
|
|
|
|
return (neg ? '-' : '') + numStr + ' ' + unit
|
|
}
|
|
|
|
window.onload = function () {
|
|
const elements = document.getElementsByClassName('file-size')
|
|
for (let i = 0; i < elements.length; i++)
|
|
elements[i].innerHTML = page.getPrettyBytes(parseInt(elements[i].innerHTML))
|
|
|
|
page.lazyLoad = new LazyLoad()
|
|
}
|