Last active
July 28, 2021 08:48
-
-
Save Ghost---Shadow/23a484a3fe69b20aee6e7b5edbf40284 to your computer and use it in GitHub Desktop.
Sorts the disable_polymer=true Youtube Watch Later playlist by video length
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
/** | |
USAGE | |
1. Open the playlist you want | |
2. Right click > Inspect element > Console | |
3. Copy this and paste. Hit enter. | |
4. For watch later make sure to click the Edit button | |
EDIT: Not all playlists have hours. | |
*/ | |
const table = document.getElementById("pl-video-table") | |
const rows = Array.from(table.rows) | |
const toSeconds = s => s.split(':').map(v => parseInt(v)).reverse().reduce((acc,e,i) => acc + e * Math.pow(60,i)) | |
const getTimestamp = row => toSeconds(row.children[6].children[0].children[0].innerText) | |
const sortedRows = rows.sort((row1, row2) => getTimestamp(row1) > getTimestamp(row2)) | |
sortedRows.forEach(row => table.appendChild(row)) | |
// For also printing the total playlist length | |
let seconds = rows.reduce((acc,e) => acc + getTimestamp(e),0) | |
let mins = parseInt(seconds / 60) | |
seconds %= 60 | |
let hours = parseInt(mins / 60) | |
mins %= 60 | |
console.log(hours+":"+mins+":"+seconds) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
// TODO: Handle NaN