Created
January 2, 2018 22:28
-
-
Save rkotov93/c9c0741170d57d49785e842bd731ec0c to your computer and use it in GitHub Desktop.
Prints VK music on the page sorted by duration
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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