This repository has been archived by the owner on Jan 5, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update console-related scripts (#140)
- Loading branch information
1 parent
8df4725
commit 11166af
Showing
10 changed files
with
98 additions
and
140 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,4 +35,5 @@ | |
} | ||
</style> | ||
|
||
<!-- SCRIPTS --> | ||
<!-- SCRIPTS --> | ||
<script src="/js/console/banner.js"></script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { convertStorageUnit } from '/modules/utils/storage.js'; | ||
|
||
|
||
(function () { | ||
const logStorage = true; | ||
|
||
if ('storage' in navigator) { | ||
navigator.storage.estimate().then((estimate) => { | ||
const { quota, usage, usageDetails } = estimate; | ||
|
||
console.info(`%c[Storage]%c Using ${convertStorageUnit(usage)} of ${convertStorageUnit(quota)}`, 'color: DarkOrchid', 'color: inherit'); | ||
console.groupCollapsed(`%c[Storage]%c Usage Details (${convertStorageUnit(usage)})`, 'color: DarkOrchid', 'color: inherit'); | ||
for (const key in usageDetails) { | ||
console.debug(`%c${key}%c ${convertStorageUnit(usageDetails[key])}`, 'color: DarkOrchid', 'color: inherit'); | ||
} | ||
console.groupEnd(); | ||
}); | ||
} | ||
|
||
|
||
function calculateStorageSize(storageType, storageName) { | ||
let size = {}; | ||
|
||
let totalSize = 0, | ||
keyLength, key; | ||
|
||
for (key in storageType) { | ||
if (!storageType.hasOwnProperty(key)) { | ||
continue; | ||
} | ||
keyLength = ((storageType[key].length + key.length) * 2); | ||
totalSize += keyLength; | ||
|
||
size[key] = keyLength; | ||
}; | ||
|
||
if (logStorage === false) { | ||
// EXAMPLE: [Storage] localStorage: 2.65 KB | ||
console.info(`%c[Storage]%c ${storageName}: ${convertStorageUnit(totalSize)}`, "color: DarkOrchid", "color: inherit"); | ||
return; | ||
} | ||
|
||
// sort by key name (alphabetical) | ||
size = Object.fromEntries(Object.entries(size).sort()); | ||
|
||
console.groupCollapsed(`%c[Storage]%c ${storageName} (${convertStorageUnit(totalSize)})`, "color: DarkOrchid", "color: inherit"); | ||
for (key in size) { | ||
console.debug(`${key} = ${convertStorageUnit(size[key])}`); | ||
} | ||
console.groupEnd(); | ||
} | ||
|
||
|
||
if ('localStorage' in window) { | ||
calculateStorageSize(localStorage, 'localStorage'); | ||
} | ||
|
||
if ('sessionStorage' in window) { | ||
calculateStorageSize(sessionStorage, 'sessionStorage'); | ||
} | ||
})(); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/** | ||
* Convert bytes to human-readable storage units | ||
* @param {number} bytes - The number of bytes | ||
* @returns {string} - The human-readable storage unit (e.g., 1.2 KiB) | ||
*/ | ||
export const convertStorageUnit = (bytes) => { | ||
const units = ['B', 'KiB', 'MiB', 'GiB', 'TiB']; | ||
let unitIndex = 0; | ||
while (bytes >= 1024 && unitIndex < units.length - 1) { | ||
bytes /= 1024; | ||
unitIndex++; | ||
} | ||
return `${bytes.toFixed(1)} ${units[unitIndex]}`; | ||
}; |