Minor fixes after testing in FF
[raitv.user.js] / raitv.user.js
1 // ==UserScript==
2 // @name        RaiTV video
3 // @description Turn RaiTV silverlight objects into video tags
4 // @namespace   http://oblomov.myopenid.com
5 // @include     http://rai.tv/*
6 // @include     http://www.rai.tv/*
7 // @author      Giuseppe "Oblomov" Bilotta
8 // @version     20130321
9 // ==/UserScript==
10
11 (function() {
12
13         function getURL(name) {
14                 var list = document.getElementsByName(name) ;
15                 if (list && list[0]) {
16                         return list[0].content;
17                 } else {
18                         return null;
19                 }
20         }
21
22         var urls = {
23                 std: getURL('videourl'),
24                 mp4: getURL('videourl_mp4'),
25                 wmv: getURL('videourl_wmv'),
26                 h264: getURL('videourl_h264'),
27                 m3u8: getURL('videourl_m3u8'),
28         }
29
30         function H5video(fmt) {
31                 if (urls[fmt]) {
32                         return '<source src="' + urls[fmt] + '" ' + (fmt == 'std' ? '' : 'type="video/' + fmt + '" ') + '/>'
33                 } else {
34                         return '';
35                 }
36         }
37
38         var sch = document.getElementById("silverlightControlHost");
39         if (sch) {
40                 // prevent other JS with messing with this element further
41                 sch.id = 'html5videoHost';
42                 sch.innerHTML = "<video style='width:100%; height:100%' controls>" +
43                         H5video('mp4') + H5video('wmv') +
44                         H5video('h264') + H5video('m3u8') +
45                         H5video('std')
46                         "</video>";
47         }
48 })();