Export Youtube Playlist in plaintext

Shows a list of the playlist video names in plaintext to be easily copied

当前为 2020-01-11 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Export Youtube Playlist in plaintext
// @namespace    1N07
// @version      0.4
// @description  Shows a list of the playlist video names in plaintext to be easily copied
// @author       1N07
// @require      https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @include        https://www.youtube.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    var listCreationAllowed = true;
    var urlAtLastCheck = "";
    setInterval(function(){
        if(urlAtLastCheck != window.location.href)
        {
            urlAtLastCheck = window.location.href;
            if(urlAtLastCheck.includes("/playlist?list="))
                InsertButtonASAP();
        }
    }, 100);


    function InsertButtonASAP()
    {
        let buttonInsertInterval = setInterval(function(){
            //wait for possible previous buttons to stop existing (due to how youtube loads pages) and for the space for the new button to be available
            if($("#exportPlainTextList").length == 0 && $("ytd-playlist-sidebar-secondary-info-renderer > #owner-container").length > 0)
            {
                $("ytd-playlist-sidebar-secondary-info-renderer > #owner-container").parent().after("<button id='exportPlainTextList'>Export as Plaintext</button>");
                $("#exportPlainTextList").click(ScrollUntillAllVisible);
                clearInterval(buttonInsertInterval);
            }
        }, 100);
    }

    function ScrollUntillAllVisible()
    {
        if(!listCreationAllowed)
            return;

        listCreationAllowed = false;
        $("#exportPlainTextList").after(`<p id="listBuildMessage" style="color: red; font-size: 1.33em;">Getting list... please wait.</p>`);
        let numOfVideosInPlaylist = $("ytd-playlist-sidebar-renderer.ytd-browse > #items #stats > yt-formatted-string.ytd-playlist-sidebar-primary-info-renderer:first").text().replace(/(\D+|\s+)/g, '');
        let scrollInterval = setInterval(function(){
            if($("yt-formatted-string#index.ytd-playlist-video-renderer").last().text() != numOfVideosInPlaylist)
                $(document).scrollTop($(document).height());
            else
            {
                BuildAndDisplayList();
                clearInterval(scrollInterval);
            }
        }, 100);
    }

    function BuildAndDisplayList()
    {
        let list = "";
        $("ytd-playlist-video-renderer #content #video-title").each(function(){
            list += $(this).attr("title") + "\n";
        });
        $("body").append('<div id="listDisplayContainer" style="position: fixed; z-index: 9999; top: 5%; right: 5%; background-color: gray; padding: 10px; border-radius: 5px;"><button style="float: right;" id="closeTheListThing">Close</button><textarea style="width: 50vw; height: 80vh; max-width: 90vw; max-height: 90vh;">'+list+'</textarea></div>');
        $("#listBuildMessage").remove();
        $("#closeTheListThing").click(function(){
            $("#listDisplayContainer").remove();
            listCreationAllowed = true;
        });
    }

})();