3 // @description Turn RaiTV silverlight objects into video tags
4 // @namespace http://oblomov.myopenid.com
5 // @include http://rai.tv/*
6 // @include http://rai.it/*
7 // @include http://www.rai.tv/*
8 // @include http://www.rai.it/*
9 // @author Giuseppe "Oblomov" Bilotta
15 function getURL(name) {
16 var list = document.getElementsByName(name) ;
17 if (list && list[0]) {
18 return list[0].content;
25 std: getURL('videourl'),
26 mp4: getURL('videourl_mp4'),
27 wmv: getURL('videourl_wmv'),
28 h264: getURL('videourl_h264'),
29 m3u8: getURL('videourl_m3u8'),
32 function srctag(url, av, fmt) {
35 return '<source src="' + url + '" ' + (fmt ? 'type="' + av + '/' + fmt + '" ' : '') + '/>'
38 function H5video(fmt) {
39 return srctag(urls[fmt], 'video', (fmt == 'std' ? null : fmt));
44 var a = document.createElement('a');
46 a.innerHTML = fmt.toUpperCase();
47 a.style='font-weight:bold;margin-left:1em;color:white';
53 var sch = document.getElementById("silverlightControlHost");
55 // if we are on a page that defines the videourl* metas, go straight to creating
58 // prevent other JS with messing with this element further
59 sch.id = 'html5mediaHost';
60 sch.innerHTML = "<video style='width:100%; height:100%' controls>" +
61 H5video('mp4') + H5video('wmv') +
62 H5video('h264') + H5video('m3u8') +
64 "<h3>Sorry, no supported video format found :-(</h3></video>";
65 console.log(sch, 'hacked');
67 var list = document.createElement("li");
69 list.innerHTML = '<span>Download:</span>';
79 // find place to append the list to:
80 var specs = sch.parentNode.parentNode.previousElementSibling.getElementsByTagName('ul');
81 if (specs && specs[0]) {
82 specs[0].appendChild(list);
83 console.log(list, 'enumerated and appended');
85 console.log(list, 'enumerated, but not appended');
90 // hack the play* JS functions
92 window.playTg = function (liveTg, video, h264, androidUrl) {
93 var dataP = new Date();
95 ggP = dataP.getDate() + "-";
96 mmP = dataP.getMonth() + 1 + "-";
97 aaaaP = 1900 + dataP.getYear();
98 // stop loading any current audio/video
99 if (sch.firstChild && sch.firstChild.src) {
100 console.log('stopping current A/V');
101 sch.firstChild.src = '';
103 sch.innerHTML = "<video width='258' height='195' controls autoplay>" +
104 srctag(h264, 'video', 'h264') +
105 srctag(androidUrl, 'video') +
106 srctag(video, 'video') +
107 "<h3>Sorry, no supported video format found :-(</h3></video>";
108 setNielsen(location.href + '&video=' + liveTg + '&data=' + ggP + mmP + aaaaP + '', true);
109 console.log('playTg', liveTg, video, h264, androidUrl)
111 console.log('playTg hacked');
113 if (window.playAudio) {
114 window.playAudio = function (grrEdizione, mediaUrl, mediatype) {
115 var dataP = new Date();
117 ggP = dataP.getDate() + "-";
118 mmP = dataP.getMonth() + 1 + "-";
119 aaaaP = 1900 + dataP.getYear();
120 // stop loading any current audio/video
121 if (sch.firstChild && sch.firstChild.src) {
122 console.log('stopping current A/V');
123 sch.firstChild.src = '';
125 sch.innerHTML = "<audio width='258' height='35' controls autoplay>" +
126 srctag(mediaUrl, 'audio') +
127 "<h3>Sorry, no supported audio format found :-(</h3></audio>";
128 setNielsen(location.href + '&audio=' + grrEdizione + '&data=' + ggP + mmP + aaaaP + '', true);
129 console.log('playAudio', grrEdizione, mediaUrl, mediatype);
131 console.log('playAudio hacked');