mirror of
https://github.com/BobbyWibowo/lolisafe.git
synced 2024-12-14 16:36:21 +00:00
3a398721b5
* Replaced all instances of getElementById and getElementsByClassName with querySelector or querySelectorAll. * Updated utilsController.js to stop disabling no-async-promise-executor eslint rule. * Removed unused lines in dashboard.njk. * Refactored maxFileSize to maxSize in home.{css,js,njk}. * Updated ClamAV codes in lolisafe.js. No more pinging. Since querying version will also check connection anyway. * Option "Upload to album" in homepage is now selectable. Selecting this option will restore the uploader to not associate files with an album. * Fixed uploader to properly respect server's max file size. Also updated error message of file size to use MB instead of MiB. * Creating an album from homepage will automatically select the album. * Updated Dropzone.js to v5.5.0. * Bumped v1 & v3 version strings. * Various other small fixes.
30 lines
926 B
JavaScript
30 lines
926 B
JavaScript
/* global LazyLoad */
|
|
|
|
const page = {
|
|
lazyLoad: null
|
|
}
|
|
|
|
page.getPrettyBytes = function (num, si) {
|
|
// MIT License
|
|
// Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
if (!Number.isFinite(num)) return num
|
|
|
|
const neg = num < 0 ? '-' : ''
|
|
const scale = si ? 1000 : 1024
|
|
if (neg) num = -num
|
|
if (num < scale) return `${neg}${num} B`
|
|
|
|
const exponent = Math.min(Math.floor(Math.log10(num) / 3), 8) // 8 is count of KMGTPEZY
|
|
const numStr = Number((num / Math.pow(scale, exponent)).toPrecision(3))
|
|
const pre = (si ? 'kMGTPEZY' : 'KMGTPEZY').charAt(exponent - 1) + (si ? '' : 'i')
|
|
return `${neg}${numStr} ${pre}B`
|
|
}
|
|
|
|
window.onload = function () {
|
|
const elements = document.querySelectorAll('.file-size')
|
|
for (let i = 0; i < elements.length; i++)
|
|
elements[i].innerHTML = page.getPrettyBytes(parseInt(elements[i].innerHTML.replace(/\s*B$/i, '')))
|
|
|
|
page.lazyLoad = new LazyLoad()
|
|
}
|