Skip to content

Instantly share code, notes, and snippets.

@rkotov93
Created January 2, 2018 22:28
Show Gist options
  • Save rkotov93/c9c0741170d57d49785e842bd731ec0c to your computer and use it in GitHub Desktop.
Save rkotov93/c9c0741170d57d49785e842bd731ec0c to your computer and use it in GitHub Desktop.
Prints VK music on the page sorted by duration
const getRows = () => {
const rowsObj = document.getElementsByClassName('audio_row_with_cover')
return Object.keys(rowsObj).map((k) => { return rowsObj[k] })
}
const duration = (row) => {
const durationStr = row.getElementsByClassName('audio_row__duration')[0].innerHTML
return parseFloat(durationStr.replace(':', '.'))
}
const sortByDuration = (rows) => {
rows.sort((a, b) => { return duration(a) - duration(b) })
return rows.reverse()
}
const formatList = (rows) => {
return rows.map((row) => {
return [
row.getElementsByClassName('audio_row__title_inner')[0].innerHTML,
duration(row)
]
})
}
const rows = getRows()
const items = formatList(sortByDuration(rows))
items.forEach((item) => {
console.log(item[0], item[1])
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment