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== // ==UserScript==
// @name Shared IP Manager // @name Shared IP Manager
// @namespace http://tampermonkey.net/ // @namespace http://tampermonkey.net/
// @version 1.1.0 // @version 1.1.1
// @description Transform shared IP overlay into searchable table format // @description Transform shared IP overlay into searchable table format
// @author Ryahn // @author Ryahn
// @match *://*/* // @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.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>`; typeHeader.innerHTML = `Type <span id="type-sort-icon" style="margin-left: 5px;">↕</span>`;
// Usage header // Usage header (sortable)
const usageHeader = document.createElement('th'); const usageHeader = document.createElement('th');
usageHeader.style.cssText = `padding: 10px 12px; text-align: left; font-weight: 600; color: #959595; white-space: nowrap;`; usageHeader.id = 'sort-usage';
usageHeader.textContent = '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 // Append all headers to row
headerRow.appendChild(usernameHeader); headerRow.appendChild(usernameHeader);
@ -413,14 +414,28 @@
} else if (column === 'type') { } else if (column === 'type') {
aValue = a.cells[5] ? a.cells[5].textContent.trim().toLowerCase() : ''; aValue = a.cells[5] ? a.cells[5].textContent.trim().toLowerCase() : '';
bValue = b.cells[5] ? b.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 console.log('Comparing:', aValue, 'vs', bValue); // Debug log
if (direction === 'asc') { if (column === 'usage') {
return aValue.localeCompare(bValue); // Numerical comparison for usage
if (direction === 'asc') {
return aValue - bValue;
} else {
return bValue - aValue;
}
} else { } else {
return bValue.localeCompare(aValue); // String comparison for username and type
if (direction === 'asc') {
return aValue.localeCompare(bValue);
} else {
return bValue.localeCompare(aValue);
}
} }
}); });
@ -486,6 +501,28 @@
this.style.backgroundColor = '#101113'; 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 // Replace overlay content
overlay.innerHTML = ''; overlay.innerHTML = '';
overlay.appendChild(tableContainer); overlay.appendChild(tableContainer);