Last active
August 29, 2015 14:17
-
-
Save forestrf/635fcaed4a9d100032cd to your computer and use it in GitHub Desktop.
Youtube Playlist 2 HTML
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tabla_videos = document.getElementById("pl-video-table"); | |
var boton_siguiente = tabla_videos.nextSibling.nextSibling; | |
console.log(tabla_videos); | |
console.log(boton_siguiente); | |
carga_mas_videos(function() { | |
//Todos los vídeos están cargados | |
console.log('Videos loaded. Generating html.'); | |
var videos = tabla_videos.getElementsByTagName("tr"); | |
var videos_length = videos.length; | |
var borrados = ""; | |
var todos = ""; | |
for (var i = 0; i < videos_length; i++) { | |
var url = videos[i].getElementsByClassName("pl-video-title")[0].getElementsByTagName("a")[0].href; | |
url = url.substring(0, url.indexOf("&")); | |
var uploader = "No hay uploader"; | |
var uploader = videos[i].getElementsByClassName("pl-video-owner")[0].getElementsByTagName("a"); | |
uploader = uploader.length > 0 ? uploader[0].innerHTML.trim() : "No hay uploader"; | |
var titulo = videos[i].getElementsByClassName("pl-video-title-link")[0].innerHTML; | |
titulo = titulo.trim(); | |
var enlace ='<li><a href="' + url + '">' + encodedStr(uploader + " ::: " + titulo) + '</a></li>\n'; | |
if (videos[i].getElementsByClassName("pl-video-owner")[0].innerHTML === "") { | |
// Vídeo borrado | |
borrados += enlace; | |
} | |
todos += enlace; | |
} | |
html = "Press Ctrl+s to save it<p>\n<h3>Borrados</h3><ol>\n" + borrados + "</ol><hr/>\n<h3>Todos</h3><ol>\n" + todos + "</ol>"; | |
myWindow = window.open("data:text/html," + encodeURIComponent(html), "_blank", "width=600,height=800,location=0,toolbar=0,resizable=1,scrollbars=1"); | |
myWindow.focus(); | |
}); | |
function encodedStr(txt) { | |
return txt.replace(/[\u00A0-\u9999<>\&]/gim, function(i) { | |
return '&#'+i.charCodeAt(0)+';'; | |
}) | |
}; | |
function carga_mas_videos(callback) { | |
boton_siguiente = tabla_videos.nextSibling.nextSibling; | |
if (boton_siguiente.click) { | |
boton_siguiente.click(); | |
setTimeout(carga_mas_videos, 100); | |
} else { | |
callback(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment