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.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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;
    }
})();