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.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Reddit Youtube Playlist Maker
// @namespace    https://greasyfork.org/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;
    }
})();