Convert embedded Real/Quicktime/WindowsMedia/Google VLC and other audio/video media player tags to links, so you can open them in an external player.
This script is by default only enabled for the ifilm, google video and 3voor12.vpro.nl sites. You can change that when you install it, or afterwards using the "Tools -> Manage User Scripts..." menu item.
2005-07-25: Updated to support Greasemonkey version 0.3.5.
2005-06-29: Updated version. Added preliminary google video support (which means you don't have to install the google player).
There are still some issues with the google video support: you need to wait untill the whole page is downloaded before clicking the "Play" links works, and some (all?) videos send out the wrong content-type, which means you should use RightClick -> Copy link location and paste the link into your player (directly opening those links will result in a HUGE garbled mess on your window).
download script (or use right-click -> "install user script").
Note: You need the Firefox browser with the GreaseMonkey extension to run this script. This script is guaranteed to work well on the 3 voor 12 and ifilm sites, but it should work for most. Feedback and patches are appreciated.
Code:
// ==UserScript==
// @name Embedded Player -> Link converter
// @namespace http://zeekat.nl/downloads/greasemonkey/3voor12
// @description Replaces embedded Real/Quicktime/WindowsMedia player tags with a clickable link, so you can open them in an external player. Works well on 3voor12.vpro.nl and ifilm. With preliminary google video support.
// @include http://3voor12.vpro.nl/*
// @include http://www.vpro.nl/*
// @include http://www.ifilm.com/*
// @include http://video.google.com/*
// ==/UserScript==
(function() {
function fakePlugins() {
navigator.plugins.refresh = function () { return true };
navigator.plugins["Google VLC multimedia plugin 1.0"] =
navigator.plugins["Google VLC multimedia plugin 1.0"] ||
{
object: true,
versionInfo: "Google VLC multimedia plugin 1.0"
};
}
// get attribute values irrespective of case
function iAtt(tag,name) {
return(
tag.getAttribute( name ) ||
tag.getAttribute( name.toUpperCase() ) ||
tag.getAttribute( name.toLowerCase() )) ;
}
window.addEventListener("load", function() {
function processTags(tagname,isRetry) {
fakePlugins();
var tags = document.getElementsByTagName(tagname);
for (var i = 0; i < tags.length; i++) {
var tag = tags.item(i);
/* for (var a in tag) {
}*/
var typeMatch = new RegExp("(?:(?:audio|video)/(?:(x-(?:pn-)?realaudio(?:-plugin)?)|(quicktime)|(x-ms-.*|x-mplayer.*)|(.*)))|(application/x-(?:google-)vlc-plugin)$","i");
var matches = typeMatch.exec(iAtt(tag,"type"));
if (matches && matches.length > 0) {
var src = iAtt(tag,"src") || iAtt(tag,"target");
if (!src || src.length == 0) {
try {
tag.parentNode.removeChild(tag); // remove control bars etc.
}
catch (e) {
}
}
else {
var humanType;
var type;
if (matches[1]) {
humanType = 'Real';
type = 'audio/x-pn-realaudio';
}
else if (matches[2]) {
humanType = 'QuickTime';
type = 'video/quicktime';
}
else if (matches[3]) {
humanType = 'Windows Media';
type = matches[0];
}
else if (matches[4]) {
humanType = matches[4];
type = matches[4];
}
else if (matches[5]) {
humanType = "(Google) VLC";
type = matches[5];
}
var title = iAtt(tag,"title");
if (!title) {
title = src;
}
title = humanType+' stream: '+title;
var width = tag.style.width || iAtt(tag,"width");
var height = tag.style.height || iAtt(tag,"height");
var button = createButton(src,type,title,width,height);
tag.parentNode.replaceChild(button, tag);
}
}
}
setTimeout(function() { processTags(tagname, true) },500);
}
processTags("object");
processTags("embed");
}, false);
function createButton(src, type, title,width,height) {
var link = document.createElement("a");
link.type = type;
if (src.match(/(rtsp|mms):\/\//i)) {
link.href = 'data: '+type+', '+src;
}
else {
link.href = src;
}
link.style.textDecoration = 'none';
var button = document.createElement("button");
button.appendChild(document.createTextNode(title));
button.style.color = '#fff';
button.style.backgroundColor = '#080';
button.style.fontWeight = 'bold';
if (width) {
button.style.width = width;
}
if (height) {
button.style.height = height;
}
link.appendChild(button);
return link;
}
})();
