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.

// ==UserScript==
// @name         Reddit Youtube Playlist Maker
// @namespace    https://gf.qytechs.cn/en/scripts/20246-reddit-youtube-playlist-maker
// @version      0.1.3
// @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.
// @author       You
// @match        *://www.reddit.com/r/videos*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
    if (document.URL.indexOf("reddit.com/r/videos") > -1){
    
    var re1 = /youtube.com\/watch\?v=\S{11}/g;
    var re2 = /youtu.be\/\S{11}/g;
    var videos = document.body.innerHTML.match(re2);
    videos = videos.concat(document.body.innerHTML.match(re1));
    
    //Remove duplicat videos
    videos = Array.from(new Set(videos));
    
    //Filter to just video ids
    for (var i = 0; i < videos.length; i++){
        videos[i] = videos[i].replace(/youtu.be\//, '');
        videos[i] =  videos[i].replace(/youtube.com\/watch\?v=/, '');
    }
    
    var crap = '">youtu.be<';
    videos.splice(videos.indexOf(crap),1);
    
    //console.log(videos);
    
    // Create youtube link
    var videoUrl = "http://www.youtube.com/watch_videos?video_ids=";
    videoUrl += videos;
    
    var html = '<a target="_blank" style="position: fixed; bottom: 10px;"  \
    title="Note: Youtube Limits this to 20 videos, no way around it." href="'
    +videoUrl +'">Open Youtube Playlist</a>';
    
    document.body.innerHTML = html + document.body.innerHTML;
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址