Skip to content

Instantly share code, notes, and snippets.

@ChiChou
Created February 25, 2019 16:29
Show Gist options
  • Save ChiChou/be0679970488e6c14a612203a4c1d996 to your computer and use it in GitHub Desktop.
Save ChiChou/be0679970488e6c14a612203a4c1d996 to your computer and use it in GitHub Desktop.
opensource.apple.com sort by version
(() => {
const trs = document.querySelector('table').querySelectorAll('tr')
const rows = [].slice.call(trs, 3, trs.length - 1)
const footer = trs[trs.length - 1]
const sorted = rows.sort((a, b) => {
const parse = tr => tr.querySelector('td:nth-of-type(2) a').textContent
.match(/((\d+\.?)+)\.tar\.gz/)[1]
.split('.')
.map(s => parseInt(s, 10))
const u = parse(a), v = parse(b)
for (let i = 0; i < Math.max(u.length, v.length); i++)
if (u[i] != v[i])
return u[i] - v[i]
})
const parent = rows[0].parentNode
rows.forEach(tr => parent.removeChild(tr))
sorted.forEach(tr => parent.insertBefore(tr, footer))
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment