Thank You! The script works and is very useful! There is not enough support for localization, torrent sizes larger than 1 TB and correct size calculation. There are 1024 bytes in one kilobyte, 1024 KB in one megabyte...
The size will be correct if the calculateTotal() function is adjusted:
function calculateTotal() { var kib = 0; var mib = 0; var gib = 0; var tib = 0; var total = "";
var selectedRows = document.querySelectorAll("tr.torrentsTableContextMenuTarget.selected");
// Check if selectedRows array is bigger than 0 if (selectedRows.length > 0) { // Check if selectedRows has changed if (!arraysAreEqual(previousSelectedRows, selectedRows)) { selectedRows.forEach(function (row) { var tSize = row.childNodes[3].innerHTML.split(" ");
if (tSize[1] == "KiB") { kib += parseFloat(tSize[0]); } else if (tSize[1] == "MiB") { mib += parseFloat(tSize[0]); } else if (tSize[1] == "GiB") { gib += parseFloat(tSize[0]); } else if (tSize[1] == "TiB") { tib += parseFloat(tSize[0]); } });
Thank You! The script works and is very useful! There is not enough support for localization, torrent sizes larger than 1 TB and correct size calculation. There are 1024 bytes in one kilobyte, 1024 KB in one megabyte...
The size will be correct if the calculateTotal() function is adjusted:
function calculateTotal() {
var kib = 0;
var mib = 0;
var gib = 0;
var tib = 0;
var total = "";
var selectedRows = document.querySelectorAll("tr.torrentsTableContextMenuTarget.selected");
// Check if selectedRows array is bigger than 0
if (selectedRows.length > 0) {
// Check if selectedRows has changed
if (!arraysAreEqual(previousSelectedRows, selectedRows)) {
selectedRows.forEach(function (row) {
var tSize = row.childNodes[3].innerHTML.split(" ");
if (tSize[1] == "KiB") {
kib += parseFloat(tSize[0]);
} else if (tSize[1] == "MiB") {
mib += parseFloat(tSize[0]);
} else if (tSize[1] == "GiB") {
gib += parseFloat(tSize[0]);
} else if (tSize[1] == "TiB") {
tib += parseFloat(tSize[0]);
}
});
var localTotal = kib + mib * 1024 + gib * 1048576 + tib * 1073741824;
// Check if total has changed
if (localTotal.toFixed(2) !== total) {
if (localTotal < 1000) {
total = localTotal.toFixed(2) + " KiB";
} else if (localTotal < 1024000) {
total = (localTotal / 1024).toFixed(2) + " MiB";
} else if (localTotal < 1048576000) {
total = (localTotal / 1048576).toFixed(2) + " GiB";
} else {
total = (localTotal / 1073741824).toFixed(2) + " TiB";
}
var selectedSizeTotal = document.getElementById("selectedSizeTotal");
selectedSizeTotal.innerHTML = "Selected Torrents Total Size: " + total;
}
// Update previousSelectedRows
previousSelectedRows = Array.from(selectedRows);
}
}
}
Best Regards, Olexiy