// ==UserScript== // @name Export Youtube Playlist in tab delimited text // @description Creates the current playlist as tab delimited text to be easily copied // @author 1N07 & MK // @namespace max44 // @homepage https://greasyfork.org/en/users/309172-max44 // @match *://*.youtube.com/* // @match *://*.youtu.be/* // @icon https://cdn.icon-icons.com/icons2/1488/PNG/512/5295-youtube-i_102568.png // @version 2.1.4 // @license MIT // @require https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js // @run-at document-idle // @downloadURL none // ==/UserScript== (function() { 'use strict'; //Workaround: This document requires 'TrustedHTML' assignment if (window.trustedTypes && trustedTypes.createPolicy) { if (!trustedTypes.defaultPolicy) { const passThroughFn = (x) => x; trustedTypes.createPolicy('default', { createHTML: passThroughFn, createScriptURL: passThroughFn, createScript: passThroughFn, }); } } 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() { var qRes = document.querySelectorAll("#exportTabTextList"); //Remove previous button for (let i = 0; i < qRes.length; i++) { qRes[i].remove(); } let buttonInsertInterval = setInterval(function() { var htmlButton = ""; if (document.querySelectorAll("#exportTabTextList").length == 0) { if (document.querySelectorAll("yt-page-header-renderer:not([hidden]) yt-page-header-view-model yt-flexible-actions-view-model").length > 0) { //New design qRes = document.querySelectorAll("yt-page-header-renderer:not([hidden]) yt-page-header-view-model yt-flexible-actions-view-model > div.yt-flexible-actions-view-model-wiz__action-row"); if (qRes != null && qRes.length > 0) { htmlButton = ""; qRes[0].insertAdjacentHTML("afterend", htmlButton); } qRes = document.querySelectorAll("#exportTabTextList"); if (qRes != null && qRes.length > 0) { qRes[0].onclick = ScrollUntilFullListVisible; } } else if (document.querySelectorAll("ytd-playlist-header-renderer:not([hidden]) div.ytd-playlist-header-renderer > div.play-menu.ytd-playlist-header-renderer").length > 0) { //Older new design qRes = document.querySelectorAll("div.metadata-wrapper.ytd-playlist-header-renderer > div.play-menu.ytd-playlist-header-renderer"); if (qRes != null && qRes.length > 0) { htmlButton = ""; qRes[0].insertAdjacentHTML("afterend", htmlButton); } qRes = document.querySelectorAll("#exportTabTextList"); if (qRes != null && qRes.length > 0) { qRes[0].onclick = ScrollUntilFullListVisible; } } else if (document.querySelectorAll("ytd-two-column-browse-results-renderer:not([hidden])[page-subtype='playlist'] div#contents div#header > ytd-sort-filter-header-renderer #filter-menu").length > 0) { //Workaround for very new design - add button above user created playlists qRes = document.querySelectorAll("ytd-two-column-browse-results-renderer:not([hidden])[page-subtype='playlist'] div#contents div#header > ytd-sort-filter-header-renderer #filter-menu"); if (qRes != null && qRes.length > 0) { htmlButton = ""; qRes[0].insertAdjacentHTML("afterend", htmlButton); } qRes = document.querySelectorAll("#exportTabTextList"); if (qRes != null && qRes.length > 0) { qRes[0].onclick = ScrollUntilFullListVisible; } } else if (document.querySelectorAll("ytd-two-column-browse-results-renderer:not([hidden])[page-subtype='playlist'] div#contents div#header #chips-content #scroll-container").length > 0) { //Workaround for very new design - add button above non-user created playlists qRes = document.querySelectorAll("ytd-two-column-browse-results-renderer:not([hidden])[page-subtype='playlist'] div#contents div#header #chips-content #scroll-container"); if (qRes != null && qRes.length > 0) { htmlButton = ""; qRes[0].insertAdjacentHTML("afterend", htmlButton); } qRes = document.querySelectorAll("#exportTabTextList"); if (qRes != null && qRes.length > 0) { qRes[0].onclick = ScrollUntilFullListVisible; } } else if (document.querySelectorAll("ytd-playlist-sidebar-renderer:not([hidden]) > ytd-playlist-sidebar-primary-info-renderer.style-scope.ytd-playlist-sidebar-renderer").length > 0) { //Old design qRes = document.querySelectorAll("ytd-playlist-sidebar-primary-info-renderer.style-scope.ytd-playlist-sidebar-renderer"); if (qRes != null && qRes.length > 0) { htmlButton = ""; qRes[0].insertAdjacentHTML("afterend", htmlButton); } qRes = document.querySelectorAll("#exportTabTextList"); if (qRes != null && qRes.length > 0) { qRes[0].onclick = ScrollUntilFullListVisible; } } //Check whether unavailable videos are hidden or not //var i; //var strAux = ""; //var flgHidden = false; //var myNodeList = document.querySelectorAll("#text"); //for (i = 0; i < myNodeList.length; i++) { // if (myNodeList[i].className.indexOf("style-scope ytd-alert-with-button-renderer") > -1) { // strAux = myNodeList[i].innerText; // strAux = strAux.trim(); // strAux = strAux.toLowerCase(); // if (strAux.indexOf("unavailable videos are hidden") > -1) { // flgHidden = true; // break; // } // } //} //if (flgHidden) { // $("#exportTabTextList").click(ScrollAsPossible); //Unavailable videos are hidden //} else { //$("#exportTabTextList").click(ScrollUntilFullListVisible); //} //clearInterval(buttonInsertInterval); - Do not clear interval in order to add button back if playlist is rebuilt } }, 100); } function ScrollUntilFullListVisible() { if (!listCreationAllowed) return; //Switch focus to playlist var listOfVideos = document.querySelector("ytd-browse[page-subtype='playlist'] #primary"); if (listOfVideos != null) { listOfVideos.click(); var htmlAlert = ""; listCreationAllowed = false; var qRes = document.querySelectorAll("#exportTabTextList:not(.yt-spec-button-shape-next--size-m)"); if (qRes != null && qRes.length > 0) { htmlAlert = `
Getting full list, please wait...
`; qRes[0].insertAdjacentHTML("afterend", htmlAlert); } qRes = document.querySelectorAll("#exportTabTextList.yt-spec-button-shape-next--size-m"); if (qRes != null && qRes.length > 0) { htmlAlert = `Getting full list, please wait...
`; qRes[0].insertAdjacentHTML("afterend", htmlAlert); } let scrollInterval = setInterval(function(){ if (document.querySelectorAll("ytd-continuation-item-renderer.ytd-playlist-video-list-renderer").length > 0) { //$(document).scrollTop($(document).height()); document.documentElement.scrollTop = document.documentElement.scrollHeight; } else { BuildAndDisplayList(); clearInterval(scrollInterval); } }, 100); } } /*function ScrollAsPossible() { //If unavailable videos are hidden if (!listCreationAllowed) return; listCreationAllowed = false; $("#exportTabTextList").after(`Getting full list, please wait...
`); $(document).scrollTop($(document).height()); let scrollInterval2 = setInterval(function(){ if (CheckSpinner()) { $(document).scrollTop($(document).height()); } else { BuildAndDisplayList(); clearInterval(scrollInterval2); } }, 500); } function CheckSpinner() { //True if playlist is still loading var i; var myNodeList = document.querySelectorAll("#spinner"); for (i = 0; i < myNodeList.length; i++) { if (myNodeList[i].className.indexOf("style-scope ytd-continuation-item-renderer") > -1) return true; } return false; }*/ function BuildAndDisplayList() { var htmlList = "