added report-organizer
This commit is contained in:
parent
89263e5920
commit
91664ab7c7
91
report-organizer.js
Normal file
91
report-organizer.js
Normal file
@ -0,0 +1,91 @@
|
||||
// ==UserScript==
|
||||
// @name Sort Reports
|
||||
// @namespace http://tampermonkey.net/
|
||||
// @version 2024-09-18
|
||||
// @description Sort Reports
|
||||
// @author You
|
||||
// @match https://f95zone.to/reports/queue/*
|
||||
// @icon https://www.google.com/s2/favicons?sz=64&domain=f95zone.to
|
||||
// @grant none
|
||||
// ==/UserScript==
|
||||
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
window.onload = function() {
|
||||
const reportTable = document.querySelector('.structItemContainer');
|
||||
|
||||
if (!reportTable) return;
|
||||
|
||||
const sortContainer = document.createElement('div');
|
||||
sortContainer.style.textAlign = 'right';
|
||||
sortContainer.innerHTML = `
|
||||
<label for="sortType">Sort By:</label>
|
||||
<select id="sortType">
|
||||
<option value="dateAsc">Date ASC</option>
|
||||
<option value="dateDesc">Date DESC</option>
|
||||
<option value="sectionAsc">Sub-section ASC</option>
|
||||
<option value="sectionDesc">Sub-section DESC</option>
|
||||
<option value="prefixAsc">Prefix ASC</option>
|
||||
<option value="prefixDesc">Prefix DESC</option>
|
||||
</select>
|
||||
`;
|
||||
|
||||
reportTable.parentNode.insertBefore(sortContainer, reportTable);
|
||||
|
||||
document.getElementById('sortType').addEventListener('change', function() {
|
||||
const sortValue = this.value;
|
||||
const rows = Array.from(reportTable.querySelectorAll('.structItem'));
|
||||
|
||||
switch (sortValue) {
|
||||
case 'dateAsc':
|
||||
sortRows(rows, '.structItem-latestDate', true, 'date');
|
||||
break;
|
||||
case 'dateDesc':
|
||||
sortRows(rows, '.structItem-latestDate', false, 'date');
|
||||
break;
|
||||
case 'sectionAsc':
|
||||
sortRows(rows, '.structItem-forum a', true);
|
||||
break;
|
||||
case 'sectionDesc':
|
||||
sortRows(rows, '.structItem-forum a', false);
|
||||
break;
|
||||
case 'prefixAsc':
|
||||
sortRows(rows, '.structItem-title', true, 'prefix');
|
||||
break;
|
||||
case 'prefixDesc':
|
||||
sortRows(rows, '.structItem-title', false, 'prefix');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
function sortRows(rows, selector, asc = true, type = 'text') {
|
||||
const sortedRows = rows.sort((a, b) => {
|
||||
let valA = a.querySelector(selector);
|
||||
let valB = b.querySelector(selector);
|
||||
|
||||
if (!valA || !valB) {
|
||||
return asc ? (valA ? -1 : 1) : (valB ? -1 : 1);
|
||||
}
|
||||
|
||||
if (type === 'date') {
|
||||
valA = parseInt(valA.getAttribute('data-time')) * 1000;
|
||||
valB = parseInt(valB.getAttribute('data-time')) * 1000;
|
||||
return asc ? valA - valB : valB - valA;
|
||||
}
|
||||
|
||||
if (type === 'prefix') {
|
||||
valA = valA.innerText.trim().split(' - ')[0];
|
||||
valB = valB.innerText.trim().split(' - ')[0];
|
||||
return asc ? valA.localeCompare(valB) : valB.localeCompare(valA);
|
||||
}
|
||||
|
||||
valA = valA.innerText.trim();
|
||||
valB = valB.innerText.trim();
|
||||
return asc ? valA.localeCompare(valB) : valB.localeCompare(valA);
|
||||
});
|
||||
|
||||
sortedRows.forEach(row => reportTable.appendChild(row));
|
||||
}
|
||||
};
|
||||
})();
|
||||
Loading…
x
Reference in New Issue
Block a user