Reddit Youtube Playlist Maker

This will create a small link at the bottom left of reddit.com/r/videos to open a playlist of the videos on the page.

  1. // ==UserScript==
  2. // @name Reddit Youtube Playlist Maker
  3. // @namespace https://greasyfork.org/en/scripts/20246-reddit-youtube-playlist-maker
  4. // @version 0.1.3
  5. // @description This will create a small link at the bottom left of reddit.com/r/videos to open a playlist of the videos on the page.
  6. // @author You
  7. // @match *://www.reddit.com/r/videos*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. if (document.URL.indexOf("reddit.com/r/videos") > -1){
  14. var re1 = /youtube.com\/watch\?v=\S{11}/g;
  15. var re2 = /youtu.be\/\S{11}/g;
  16. var videos = document.body.innerHTML.match(re2);
  17. videos = videos.concat(document.body.innerHTML.match(re1));
  18. //Remove duplicat videos
  19. videos = Array.from(new Set(videos));
  20. //Filter to just video ids
  21. for (var i = 0; i < videos.length; i++){
  22. videos[i] = videos[i].replace(/youtu.be\//, '');
  23. videos[i] = videos[i].replace(/youtube.com\/watch\?v=/, '');
  24. }
  25. var crap = '">youtu.be<';
  26. videos.splice(videos.indexOf(crap),1);
  27. //console.log(videos);
  28. // Create youtube link
  29. var videoUrl = "http://www.youtube.com/watch_videos?video_ids=";
  30. videoUrl += videos;
  31. var html = '<a target="_blank" style="position: fixed; bottom: 10px;" \
  32. title="Note: Youtube Limits this to 20 videos, no way around it." href="'
  33. +videoUrl +'">Open Youtube Playlist</a>';
  34. document.body.innerHTML = html + document.body.innerHTML;
  35. }
  36. })();