// ==UserScript==
// @name City.fi video download link
// @namespace http://vyznev.net/
// @description Adds a download link to the city.fi video pages
// @include http://*city.fi/antitv/klippi/*
// ==/UserScript==
//
// v1.2 (2007-11-26):
// * site redesigned again, updated script to work with new
// URLs and embed attributes
//
// v1.1 (2007-09-19):
// * player id changed on site, change script accordingly
// * use textContent to get title text
var page_id = /klippi\/([0-9]+)/.exec( window.location.href );
if ( !page_id ) return;
page_id = page_id[1];
var embed = document.getElementById('cplay.swf');
if ( !embed ) return;
var video_id = /video_id=([0-9]+)/.exec( embed.getAttribute('src') );
if ( !video_id ) return;
video_id = video_id[1];
var h1 = document.getElementsByTagName('h1')[0];
if ( !h1 ) return;
var name = h1.textContent;
var url = 'http://videot.city.fi/push/video.php/cityvideo_' + page_id;
if ( name ) url += '_' + encodeURIComponent( name.replace(/\s/g, "_") );
url += '.flv?id=' + video_id;
var link = document.createElement('a');
link.href = url;
link.appendChild( document.createTextNode('download') );
link.style.fontWeight = 'bold';
link.style.fontVariant = 'small-caps';
link.style.textDecoration = 'none';
link.style.display = 'block';
link.style.cssFloat = 'right';
h1.parentNode.insertBefore( link, h1 );