Reverse YouTube Watch Later List

Reverses the list order for the Youtube Watch Later page

  1. // ==UserScript==
  2. // @id ReverseYouTubeWatchLaterlist
  3. // @name Reverse YouTube Watch Later List
  4. // @namespace http://kjung.ca
  5. // @version 0.2
  6. // @description Reverses the list order for the Youtube Watch Later page
  7. // @match https://www.youtube.com/*
  8. // @match http://www.youtube.com/*
  9. // @copyright 2014+, Kevin Jung
  10. // @require https://code.jquery.com/jquery-latest.min.js
  11. // @require https://greasyfork.org/scripts/1003-wait-for-key-elements/code/Wait%20for%20key%20elements.js?version=2765
  12. // ==/UserScript==
  13.  
  14. waitForKeyElements ("#pl-video-table", reverseYouTubeWatchLaterlist);
  15.  
  16. function reverseYouTubeWatchLaterlist () {
  17. $('html, body').css('display', 'none');
  18.  
  19. // Set variables.
  20. var wishListRows = [],
  21. reversedList = '';
  22.  
  23. // Loop through watch later table rows.
  24. $('#pl-video-table > tbody > tr').each(function() {
  25. var video = $(this);
  26.  
  27. // Push each video into the array.
  28. wishListRows.push(video[0]);
  29.  
  30. video.remove();
  31. });
  32.  
  33. // Reverse the item order of the array.
  34. wishListRows = wishListRows.reverse();
  35.  
  36. // Loop through each video.
  37. $.each(wishListRows, function(index, video) {
  38.  
  39. // Append the HTML contents of the video into a string.
  40. reversedList += video.outerHTML;
  41. });
  42.  
  43. // Append the string with all video HTML DOM into the watch later table.
  44. $('#pl-load-more-destination').append(reversedList);
  45.  
  46. $('html, body').css('display', 'block');
  47. }