Update shared-ip-manager.userscript.js

Added sort to usage
This commit is contained in:
Ryahn 2025-09-10 00:21:34 +00:00
parent 2733e86c8f
commit 2a267bcc05

View File

@ -1,7 +1,7 @@
// ==UserScript==
// @name Shared IP Manager
// @namespace http://tampermonkey.net/
// @version 1.1.0
// @version 1.1.1
// @description Transform shared IP overlay into searchable table format
// @author Ryahn
// @match *://*/*
@ -202,10 +202,11 @@
typeHeader.style.cssText = `padding: 10px 12px; text-align: left; border-right: 1px solid #17191b; font-weight: 600; color: #959595; white-space: nowrap; cursor: pointer; user-select: none;`;
typeHeader.innerHTML = `Type <span id="type-sort-icon" style="margin-left: 5px;">↕</span>`;
// Usage header
// Usage header (sortable)
const usageHeader = document.createElement('th');
usageHeader.style.cssText = `padding: 10px 12px; text-align: left; font-weight: 600; color: #959595; white-space: nowrap;`;
usageHeader.textContent = 'Usage';
usageHeader.id = 'sort-usage';
usageHeader.style.cssText = `padding: 10px 12px; text-align: left; font-weight: 600; color: #959595; white-space: nowrap; cursor: pointer; user-select: none;`;
usageHeader.innerHTML = `Usage <span id="usage-sort-icon" style="margin-left: 5px;">↕</span>`;
// Append all headers to row
headerRow.appendChild(usernameHeader);
@ -413,15 +414,29 @@
} else if (column === 'type') {
aValue = a.cells[5] ? a.cells[5].textContent.trim().toLowerCase() : '';
bValue = b.cells[5] ? b.cells[5].textContent.trim().toLowerCase() : '';
} else if (column === 'usage') {
// Parse usage as numbers for proper numerical sorting
aValue = parseFloat(a.cells[6] ? a.cells[6].textContent.trim() : '0') || 0;
bValue = parseFloat(b.cells[6] ? b.cells[6].textContent.trim() : '0') || 0;
}
console.log('Comparing:', aValue, 'vs', bValue); // Debug log
if (column === 'usage') {
// Numerical comparison for usage
if (direction === 'asc') {
return aValue - bValue;
} else {
return bValue - aValue;
}
} else {
// String comparison for username and type
if (direction === 'asc') {
return aValue.localeCompare(bValue);
} else {
return bValue.localeCompare(aValue);
}
}
});
// Clear tbody and re-append sorted rows
@ -486,6 +501,28 @@
this.style.backgroundColor = '#101113';
});
console.log('Adding click listener to usage header');
usageHeader.addEventListener('click', (e) => {
console.log('Usage header clicked');
e.preventDefault();
if (currentSort.column === 'usage') {
currentSort.direction = currentSort.direction === 'asc' ? 'desc' : 'asc';
} else {
currentSort.column = 'usage';
currentSort.direction = 'asc';
}
console.log('Current sort:', currentSort);
sortTable(currentSort.column, currentSort.direction);
});
// Add hover effects for usage header
usageHeader.addEventListener('mouseenter', function() {
this.style.backgroundColor = '#1a1a1a';
});
usageHeader.addEventListener('mouseleave', function() {
this.style.backgroundColor = '#101113';
});
// Replace overlay content
overlay.innerHTML = '';
overlay.appendChild(tableContainer);