From 601f9cba19c8ce18eaaf8876d743fe18ba252f1e Mon Sep 17 00:00:00 2001 From: Giuseppe Bilotta Date: Wed, 3 Apr 2013 19:57:32 +0200 Subject: [PATCH] Use script injection to work fully under Chromium --- raitv.user.js | 39 ++++++++++++++++++++++++++------------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/raitv.user.js b/raitv.user.js index 2045c6b..054cfe2 100644 --- a/raitv.user.js +++ b/raitv.user.js @@ -10,12 +10,23 @@ // @version 20130403 // ==/UserScript== -if (typeof(unsafeWindow) == 'undefined') { - unsafeWindow = window; -} +/* Since the Chrome sandbox is _extremely_ restrictive and we can't access things such as window.videoURL from the actual document, + * we have to resort to script injection to be completely cross-platform. + */ (function() { +function addScript(source) { + var script = document.createElement('script'); + script.setAttribute("type", "application/javascript"); + script.textContent = '(' + source + ')();'; + document.body.appendChild(script); +} + + +addScript( +function() { + function getURL(name) { var list = document.getElementsByName(name) ; if (list && list[0]) { @@ -23,8 +34,8 @@ if (typeof(unsafeWindow) == 'undefined') { } else { var altname = name.toUpperCase().replace('VIDEO','video'); console.log(name, altname); - console.log(unsafeWindow[name], unsafeWindow[altname]); - return unsafeWindow[altname]; + console.log(window[name], window[altname]); + return window[altname]; } } @@ -52,7 +63,7 @@ if (typeof(unsafeWindow) == 'undefined') { var a = document.createElement('a'); a.href = urls[fmt]; a.innerHTML = fmt.toUpperCase(); - a.style='font-weight:bold;margin-left:1em;color:white'; + a.setAttribute('style', 'font-weight:bold;margin-left:1em;color:white'); return a; } return null @@ -64,7 +75,7 @@ if (typeof(unsafeWindow) == 'undefined') { var a = document.createElement('a'); a.href = url; a.innerHTML = name.toUpperCase(); - a.style='font-weight:bold;margin-left:1em;color:red'; + a.setAttribute('style', 'font-weight:bold;margin-left:1em;color:red'); return a; } return null @@ -129,8 +140,8 @@ if (typeof(unsafeWindow) == 'undefined') { } // hack the play* JS functions - if (unsafeWindow.playTg) { - unsafeWindow.playTg = function (liveTg, video, h264, androidUrl) { + if (window.playTg) { + window.playTg = function (liveTg, video, h264, androidUrl) { var dataP = new Date(); var ggP, mmP, aaaaP; ggP = dataP.getDate() + "-"; @@ -139,7 +150,7 @@ if (typeof(unsafeWindow) == 'undefined') { // prevent page from refreshing, the site only checks for // the existence of object/embed, not audio/video - unsafeWindow.refreshByJS = false; + window.refreshByJS = false; // stop loading any current audio/video if (sch.firstChild && sch.firstChild.src) { @@ -179,8 +190,8 @@ if (typeof(unsafeWindow) == 'undefined') { console.log('playTg hacked'); } - if (unsafeWindow.playAudio) { - unsafeWindow.playAudio = function (grrEdizione, mediaUrl, mediatype) { + if (window.playAudio) { + window.playAudio = function (grrEdizione, mediaUrl, mediatype) { var dataP = new Date(); var ggP, mmP, aaaaP; ggP = dataP.getDate() + "-"; @@ -189,7 +200,7 @@ if (typeof(unsafeWindow) == 'undefined') { // prevent page from refreshing, the site only checks for // the existence of object/embed, not audio/video - unsafeWindow.refreshByJS = false; + window.refreshByJS = false; // stop loading any current audio/video if (sch.firstChild && sch.firstChild.src) { @@ -214,4 +225,6 @@ if (typeof(unsafeWindow) == 'undefined') { console.log('playAudio hacked'); } } +}) + })(); -- 2.32.0.93.g670b81a890