User:Elominius/common.js

/* This script extracts YouTube URLs from a page and lists them at the bottom. */ var titles=""; var a_tags=document.getElementsByTagName("a"); for (var count=46; count < a_tags.length; count++) { var current_title=a_tags[count].getAttribute("title"); var current_href=a_tags[count].getAttribute("href"); if (current_href!=null && current_href.search(/https?:\/\/(www|m).youtube.com\/watch\?v=/i) == 0 ) /* filter invalid data */ { var video_id=current_href.replace(/.*watch\?v=/,"").replace(/(.{11}).*/,"$1"); /* extract IDs */ if (video_id.length == 11) /* filter invalid data */ { titles+="\n"+video_id; if (current_title) /* filter out "null" */ { titles+="\x09"+current_title; } }   } } document.body.innerHTML+=" "+titles+" ";