forked from rDrama/rDrama
35 lines
918 B
JavaScript
35 lines
918 B
JavaScript
let sortAscending = {};
|
|
|
|
function sort_table(n) {
|
|
const table = this.event.target.parentElement.parentElement.parentElement
|
|
const rows = table.rows;
|
|
let items = [];
|
|
for (let i = 1; i < rows.length; i++) {
|
|
const ele = rows[i];
|
|
let x = rows[i].getElementsByTagName("TD")[n];
|
|
if (!('sortKey' in x.dataset)) {
|
|
x = x.getElementsByTagName('a')[0] || x;
|
|
}
|
|
let attr;
|
|
if ('sortKey' in x.dataset) {
|
|
attr = x.dataset.sortKey;
|
|
} else if ('time' in x.dataset) {
|
|
attr = parseInt(x.dataset.time);
|
|
} else {
|
|
attr = parseInt(x.innerHTML.replace(/,/g, ''));
|
|
}
|
|
items.push({ ele, attr });
|
|
}
|
|
if (sortAscending[n]) {
|
|
items.sort((a, b) => a.attr > b.attr ? 1 : -1);
|
|
sortAscending[n] = false;
|
|
} else {
|
|
items.sort((a, b) => a.attr < b.attr ? 1 : -1);
|
|
sortAscending[n] = true;
|
|
}
|
|
|
|
for (let i = items.length - 1; i--;) {
|
|
items[i].ele.parentNode.insertBefore(items[i].ele, items[i + 1].ele);
|
|
}
|
|
}
|