Support live pages too master
authorGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 11 Jul 2013 20:01:17 +0000 (22:01 +0200)
committerGiuseppe Bilotta <giuseppe.bilotta@gmail.com>
Thu, 11 Jul 2013 20:01:17 +0000 (22:01 +0200)
la7.user.js

index 2b24628..bc2039c 100644 (file)
@@ -4,6 +4,7 @@
 // @namespace  http://oblomov.myopenid.com
 // @include    http://www.la7.it/*
 // @include    http://la7.it/*
+// @include    http://live.la7.it/*
 // @author     Giuseppe "Oblomov" Bilotta
 // @version    20130326
 // ==/UserScript==
 (function() {
 
        var flashdiv = document.getElementById("FlashObject");
-       if (flashdiv) {
-               var embed = flashdiv.getElementsByTagName("embed");
+       var sCH = document.getElementById("silverlightControlHost");
+       var flashvars = {};
+       var embed;
+
+       if (sCH) {
+               embed = sCH;
+               flashvars.contentURL = urlVideoPlay;
+               flashvars.title = liveTitle;
+               console.log(flashvars);
+       } else if (flashdiv) {
+               embed = flashdiv.getElementsByTagName("embed");
                console.log(embed);
                if (!embed || !embed[0]) {
                        // done
 
                var flashvarsAR = embed.getAttribute('flashvars').split('&');
 
-               var flashvars = {};
-
                for (var i = 0; i < flashvarsAR.length; ++i) {
                        var kv = flashvarsAR[i].split('=');
                        flashvars[kv[0]] = kv[1];
                }
+       } else {
+               // done
+               return;
+       }
 
-               var video = document.createElement('video');
-               video.controls = true;
-               video.autoplay = true;
-               video.width = embed.width;
-               video.height = embed.height;
-               video.id = 'html5' + embed.id;
-               video.src = flashvars.contentURL;
-               video.title = flashvars.title;
+       var video = document.createElement('video');
+       video.controls = true;
+       video.autoplay = true;
+       video.width = embed.width || embed.clientWidth;
+       video.height = embed.height || embed.clientHeight;
+       video.id = 'html5' + embed.id;
+       video.src = flashvars.contentURL;
+       video.title = flashvars.title;
 
+       if (sCH) {
+               sCH.parentNode.insertBefore(video, embed);
+       } else if (flashdiv) {
                flashdiv.insertBefore(video, embed);
-               video.appendChild(embed);
        }
+       video.appendChild(embed);
+
+       var url_host = document.getElementById("fb-root");
+       if (!url_host) {
+               url_host = document.getElementById("___plusone_0");
+       }
+       if (url_host) {
+               url_host = url_host.parentNode;
+               var a = document.createElement('a');
+               a.href = flashvars.contentURL;
+               a.innerHTML = "Direct link";
+               a.setAttribute('style', 'font-weight:bold;margin-left:1em;padding:1ex;color:blue;display:inline-box;border:1px solid blue;border-radius:.5ex');
+               url_host.appendChild(a);
+       }
+
 })();