There are 3 previous versions of this script.
// ==UserScript==
// @name IMDB quick trailer
// @namespace lazyttrick
// @description Shortcut to trailers on IMDB. Opens in new tab.
// @include http://www.imdb.com/title/tt*/*
// @exclude http://www.imdb.com/title/tt*/trailers
// ==/UserScript==
var movieid = location.href.match(/\d+/)[0];
//insert menu below "Quicklinks"
var select = createElement('select',null,"change playIt false");
select.addEventListener('click', loadTrailersPage, false);
select.appendChild(createElement('option',{value:""},null,""));
try{
getId("tn15lhs").insertBefore(select, getId("quicklinks_select").parentNode.nextSibling);
getId("tn15lhs").insertBefore(createElement('h6',null,null,'Trailers'), select);
}catch(e){
}
function loadTrailersPage(evt)
{
//loading...
select.removeEventListener('click', loadTrailersPage, false);
select.appendChild( createElement('option', {id:"idloadingoption"}, null, "Loading..."));
GM_xmlhttpRequest({
method: 'GET',
url: 'http://www.imdb.com/title/tt'+movieid+'/videosites',
onload: function(resp) {
//remove loading...
select.removeChild(getId("idloadingoption"));
//insert options...
var arr = resp.responseText.match(/\(Flash\)\s+\([^\)]+\)/g);
for(var i=0; i<arr.length; i++){
try{
select.appendChild(
createElement('option',
{ value: arr[i].match(/\"http[^\"]+\"/)[0].replace(/\"/g,"") },
null,
""+arr[i].match(/\>[^\<]+/)[0].replace(/\>/,"")
)
);
}catch(e){
GM_log(e);
}
}
}
});
}
function playIt(evt)
{
var sel = evt.target;
if(sel.selectedIndex==0)
return;
GM_openInTab(sel.value);
}
function createElement(type, attrArray, evtListener, html)
{
var node = document.createElement(type);
for (var attr in attrArray) if (attrArray.hasOwnProperty(attr)){
node.setAttribute(attr, attrArray[attr]);
}
if(evtListener){
var a = evtListener.split(' ');
node.addEventListener(a[0], eval(a[1]), eval(a[2]));
}
if(html)
node.innerHTML = html;
return node;
}
function getId(id, parent){
if(!parent)
return document.getElementById(id);
return parent.getElementById(id);
}
function getTag(name, parent){
if(!parent)
return document.getElementsByTagName(name);
return parent.getElementsByTagName(name);
}
