Support live pages too
[la7.user.js] / la7.user.js
1 // ==UserScript==
2 // @name        La7 video
3 // @description Turn La7 embedded flash video into HTML5
4 // @namespace   http://oblomov.myopenid.com
5 // @include     http://www.la7.it/*
6 // @include     http://la7.it/*
7 // @include     http://live.la7.it/*
8 // @author      Giuseppe "Oblomov" Bilotta
9 // @version     20130326
10 // ==/UserScript==
11
12 (function() {
13
14         var flashdiv = document.getElementById("FlashObject");
15         var sCH = document.getElementById("silverlightControlHost");
16         var flashvars = {};
17         var embed;
18
19         if (sCH) {
20                 embed = sCH;
21                 flashvars.contentURL = urlVideoPlay;
22                 flashvars.title = liveTitle;
23                 console.log(flashvars);
24         } else if (flashdiv) {
25                 embed = flashdiv.getElementsByTagName("embed");
26                 console.log(embed);
27                 if (!embed || !embed[0]) {
28                         // done
29                         return;
30                 }
31                 embed = embed[0];
32
33                 var flashvarsAR = embed.getAttribute('flashvars').split('&');
34
35                 for (var i = 0; i < flashvarsAR.length; ++i) {
36                         var kv = flashvarsAR[i].split('=');
37                         flashvars[kv[0]] = kv[1];
38                 }
39         } else {
40                 // done
41                 return;
42         }
43
44         var video = document.createElement('video');
45         video.controls = true;
46         video.autoplay = true;
47         video.width = embed.width || embed.clientWidth;
48         video.height = embed.height || embed.clientHeight;
49         video.id = 'html5' + embed.id;
50         video.src = flashvars.contentURL;
51         video.title = flashvars.title;
52
53         if (sCH) {
54                 sCH.parentNode.insertBefore(video, embed);
55         } else if (flashdiv) {
56                 flashdiv.insertBefore(video, embed);
57         }
58         video.appendChild(embed);
59
60         var url_host = document.getElementById("fb-root");
61         if (!url_host) {
62                 url_host = document.getElementById("___plusone_0");
63         }
64         if (url_host) {
65                 url_host = url_host.parentNode;
66                 var a = document.createElement('a');
67                 a.href = flashvars.contentURL;
68                 a.innerHTML = "Direct link";
69                 a.setAttribute('style', 'font-weight:bold;margin-left:1em;padding:1ex;color:blue;display:inline-box;border:1px solid blue;border-radius:.5ex');
70                 url_host.appendChild(a);
71         }
72
73 })();