Hacker News new | ask | show | jobs
by droidist2 2457 days ago
Wish it was sortable by date
5 comments

Closest I could get:

`Array.from(document.querySelectorAll('table tbody tr')).sort((a, b) => { const yearA = parseInt(a.querySelector('td:nth-child(3)').innerText) || 2019, yearB = parseInt(b.querySelector('td:nth-child(3)').innerText) || 2019; return yearB - yearA; }).forEach(tr => { tr.remove(); document.querySelector('table tbody').insertAdjacentElement('afterbegin', tr) });`

Just added. Hope it doesn't break anything as that's the first Javascript I've added to an otherwise static site. Please let me know if that works!
This is doable with some JavaScript. Paste the JavaScript from this gist [1] in your console while on the web page, and the table will be sorted descending by year. Swap `bValue - aValue` on line 4 with `aValue - bValue` to sort ascending.

[1] - https://gist.github.com/bendiksolheim/307a6af9aba2c4360c75b9...

It breaks/stops at rows with blank "appeared".
Floop

document.querySelector('tbody').append(...Array.from(document.querySelector('tbody').rows).map(row => ({ row, year: parseInt(row.cells[2].textContent) || 9000 })).sort((a, b) => a.year < b.year ? -1 : a.year > b.year ? 1 : 0).map(x => x.row))

Yeah, I find it quite difficult to navigate without sorting them in chronological order...
And by users.