First draft
[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     20130320
9 // ==/UserScript==
10
11 if (typeof(unsafeWindow) == 'undefined') unsafeWindow = window;
12
13 (function() {
14
15         function getURL(name) {
16                 var list = document.getElementsByName(name) ;
17                 if (list) {
18                         return list[0].content;
19                 } else {
20                         return null;
21                 }
22         }
23
24         var urls = {
25                 std: getURL('videourl'),
26                 mp4: getURL('videourl_mp4'),
27                 wmv: getURL('videourl_wmv'),
28                 h264: getURL('videourl_h264'),
29                 m3u8: getURL('videourl_m3u8'),
30         }
31
32         function H5video(fmt) {
33                 if (urls[fmt]) {
34                         return '<source src="' + urls[fmt] + '" type="video/' + fmt + '" />'
35                 } else {
36                         return '';
37                 }
38         }
39
40         var sch = unsafeWindow.document.getElementById("silverlightControlHost");
41         if (sch) {
42                 sch.innerHTML = "<video style='width:100%; height:100%' controls>" +
43                         H5video('mp4') + H5video('wmv') +
44                         H5video('h264') + H5video('m3u8') +
45                         "</video>";
46         } else {
47                 alert("sCH not found");
48         }
49 })();