// ==UserScript==
// @name Export Youtube Playlist in tab delimited text
// @namespace 1N07 & MK
// @version 0.4.1
// @description Shows a list of the playlist video names in tab delimited text to be easily copied
// @author 1N07 & MK
// @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
// @include https://www.youtube.com/*
// @grant none
// @downloadURL 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 ($("#exportTabTextList").length == 0 && $("ytd-playlist-sidebar-secondary-info-renderer > #owner-container").length > 0) {
$("ytd-playlist-sidebar-secondary-info-renderer > #owner-container").parent().after("");
$("#exportTabTextList").click(ScrollUntillAllVisible);
clearInterval(buttonInsertInterval);
}
}, 100);
}
function ScrollUntillAllVisible() {
if (!listCreationAllowed) return;
listCreationAllowed = false;
$("#exportTabTextList").after(`
Getting list... please wait.
`);
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 = "\t\t";
/*let vTitle = "";
let vChannel = "";
let vDuration = "";
let vFull = "";
$("ytd-playlist-video-renderer #content #video-title").each(function() {
vTitle = $(this).attr("title");
if (vTitle != "[Private video]" && vTitle != "[Deleted video]") {
vFull = $(this).attr("aria-label");
vFull = vFull.replace(vTitle, "");
vFull = vFull.replace(" by ", "\t");
vFull = vFull.replace(/\w+(?=\s+ago)/g, "");
vFull = vFull.replace(/\w+(?=\s+ago)/g, "");
vFull = vFull.replace(" ago ", "\t");
list += vTitle + vFull + "\n";
} else {
list += vTitle + "\n";
}
});*/
var myNodeList = document.querySelectorAll("div");
var i;
for (i = 0; i < myNodeList.length; i++) {
if (myNodeList[i].id == "content" && myNodeList[i].className == "style-scope ytd-playlist-video-renderer") {
var mySpanList = myNodeList[i].querySelectorAll("span");
var myAList = myNodeList[i].querySelectorAll("a");
var j;
var strAux;
for (j = 0; j < mySpanList.length; j++) {
if (mySpanList[j].id == "video-title") {
strAux = mySpanList[j].innerText;
strAux = strAux.replace(/[\x0D\x0A]/g, " ");
list += "\n" + strAux.trim();
}
}
for (j = 0; j < myAList.length; j++) {
if (myAList[j].className == "yt-simple-endpoint style-scope yt-formatted-string") {
strAux = myAList[j].innerText;
strAux = strAux.replace(/[\x0D\x0A]/g, " ");
list += "\t" + strAux.trim();
}
}
for (j = 0; j < mySpanList.length; j++) {
if (mySpanList[j].className == "style-scope ytd-thumbnail-overlay-time-status-renderer") {
strAux = mySpanList[j].innerText;
strAux = strAux.replace(/[\x0D\x0A]/g, " ");
list += "\t " + strAux.trim();
}
}
}
}
$("body").append('