Stupid typo
[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://rai.it/*
7 // @include     http://www.rai.tv/*
8 // @include     http://www.rai.it/*
9 // @author      Giuseppe "Oblomov" Bilotta
10 // @version     20130322
11 // ==/UserScript==
12
13 (function() {
14
15         function getURL(name) {
16                 var list = document.getElementsByName(name) ;
17                 if (list && list[0]) {
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 srctag(url, av, fmt) {
33                 if (!url)
34                         return '' ;
35                 return '<source src="' + url + '" ' + (fmt ? 'type="' + av + '/' + fmt + '" ' : '') + '/>'
36         }
37
38         function H5video(fmt) {
39                 return srctag(urls[fmt], 'video', (fmt == 'std' ? null : fmt));
40         }
41
42         var sch = document.getElementById("silverlightControlHost");
43         if (sch) {
44                 // if we are on a page that defines the videourl* metas, go straight to creating
45                 // the video element
46                 if (urls.std) {
47                         // prevent other JS with messing with this element further
48                         sch.id = 'html5mediaHost';
49                         sch.innerHTML = "<video style='width:100%; height:100%' controls>" +
50                                 H5video('mp4') + H5video('wmv') +
51                                 H5video('h264') + H5video('m3u8') +
52                                 H5video('std') +
53                                 "<h3>Sorry, no supported video format found :-(</h3></video>";
54                         console.log(sch, 'hacked');
55                         return; // done
56                 }
57
58                 // hack the play* JS functions
59                 if (window.playTg) {
60                         window.playTg = function (liveTg, video, h264, androidUrl) {
61                                 var dataP = new Date();
62                                 var ggP, mmP, aaaaP;
63                                 ggP = dataP.getDate() + "-";
64                                 mmP = dataP.getMonth() + 1 + "-";
65                                 aaaaP = 1900 + dataP.getYear();
66                                 // stop loading any current audio/video
67                                 if (sch.firstChild && sch.firstChild.src) {
68                                         console.log('stopping current A/V');
69                                         sch.firstChild.src = '';
70                                 }
71                                 sch.innerHTML = "<video width='258' height='195' controls autoplay>" +
72                                         srctag(h264, 'video', 'h264') +
73                                         srctag(androidUrl, 'video') +
74                                         srctag(video, 'video') +
75                                         "<h3>Sorry, no supported video format found :-(</h3></video>";
76                                 setNielsen(location.href + '&video=' + liveTg + '&data=' + ggP + mmP + aaaaP + '', true);
77                                 console.log('playTg', liveTg, video, h264, androidUrl)
78                         }
79                         console.log('playTg hacked');
80                 }
81                 if (window.playAudio) {
82                         window.playAudio = function (grrEdizione, mediaUrl, mediatype) {
83                                 var dataP = new Date();
84                                 var ggP, mmP, aaaaP;
85                                 ggP = dataP.getDate() + "-";
86                                 mmP = dataP.getMonth() + 1 + "-";
87                                 aaaaP = 1900 + dataP.getYear();
88                                 // stop loading any current audio/video
89                                 if (sch.firstChild && sch.firstChild.src) {
90                                         console.log('stopping current A/V');
91                                         sch.firstChild.src = '';
92                                 }
93                                 sch.innerHTML = "<audio width='258' height='35' controls autoplay>" +
94                                         srctag(mediaUrl, 'audio') +
95                                 "<h3>Sorry, no supported audio format found :-(</h3></audio>";
96                                 setNielsen(location.href + '&audio=' + grrEdizione + '&data=' + ggP + mmP + aaaaP + '', true);
97                                 console.log('playAudio', grrEdizione, mediaUrl, mediatype);
98                         }
99                         console.log('playAudio hacked');
100                 }
101         }
102 })();