Skip to content

Instantly share code, notes, and snippets.

@eai04191
Created June 26, 2023 17:09
Show Gist options
  • Save eai04191/96baa0407df9db0a4ba3fef10f4475b9 to your computer and use it in GitHub Desktop.
Save eai04191/96baa0407df9db0a4ba3fef10f4475b9 to your computer and use it in GitHub Desktop.
function ArkWindowsSize() {
const units = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB", "ZiB", "YiB"];
function toBytes(sizeStr) {
const [value, unit] = sizeStr.split(" ");
return Number(value) * Math.pow(1024, units.indexOf(unit));
}
function fromBytes(bytes) {
let unitIndex = 0;
while (bytes >= 1024 && unitIndex < units.length - 1) {
bytes /= 1024;
unitIndex++;
}
return `${bytes.toFixed(2)} ${units[unitIndex]}`;
}
const totalBytes = [
...document.querySelectorAll("#depots table .octicon-windows"),
]
.map((e) => e.closest("tr").querySelector("td:last-of-type"))
.filter((e) => e.className === "")
.map((e) => toBytes(e.innerText))
.reduce((a, b) => a + b, 0);
return fromBytes(totalBytes);
}
ArkWindowsSize();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment