NRG video

By Yehuda B. Last update May 16, 2008 — Installed 1,785 times. Daily Installs: 6, 0, 4, 1, 0, 1, 2, 1, 2, 3, 1, 7, 1, 2, 0, 3, 0, 5, 3, 0, 2, 0, 1, 2, 5, 2, 0, 0, 1, 1, 3, 1
// NRG video user script
// version 0.5
// 2008-05-16
// Copyright (c) 2008 Yehuda B.
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.  To install it, you need
// Greasemonkey 0.7.2 or later: https://addons.mozilla.org/en-US/firefox/addon/748
// Then restart Firefox and revisit this script.
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "NRG video", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          NRG video
// @namespace     http://yehudab.com
// @description   Fix display issues in NRG (Maariv) web site. Version: 0.5
// @include       http://*.nrg.co.il/*
// @include       http://*.castup.net/PlayerSupport.inc.asp*
// @include       http://*.castup.net/Customers/nrg/*
// ==/UserScript==
function getPlayerHtml(url, width, height)
{
	return "<embed id=\"GMPlayer\" width=\"" + width + "\" height=\"" + height + "\" autostart='1' showcontrols='1' loop='0' type=\"application/x-mplayer2\" src=\"" + url + "\"/>";
}

function setGMStatus(text)
{
	if (document.getElementById("GMStatus") != null)
		document.getElementById("GMStatus").innerHTML = text;	
}

function fixFlash()
{
	var allFrames = document.getElementsByTagName("IFRAME");
	if (allFrames != null)
	{
		var i, l = allFrames.length;
		for (i = 0; i < l; i++)
		{
			if (allFrames[i].src.match(/banner/))
			{
				allFrames[i].src="about:blank";
//				allFrames[i].style.display="none";
			}
		}
	}
}

function http2mms(elementID, videoUrl, width, height)
{
	window.setTimeout(function() {
 		GM_xmlhttpRequest({
		  method:"GET",
		  url:videoUrl,
		  onload:function(details) {
			if (details.status != 200)
			{
				setGMStatus("GM failed");
				GM_log("Unable to load mms for url: " + videoUrl, 2);
			}
			else
			{
				var mmsArr = details.responseText.match(/mms:\/\/[^;]*/);
				if (mmsArr != null) 
				{
					videoUrl = mmsArr[0];
					GM_log(videoUrl);
					setGMStatus("GM playing");
					document.getElementById(elementID).innerHTML = getPlayerHtml(videoUrl, width*1.2, height*1.2);
				}
				else
				{
					setGMStatus("GM failed");
					GM_log("Unable to find mms in url: " + videoUrl, 2);
				}
			}
		  }
		});
	}, 0);
}

function fixVideo()
{
	unsafeWindow.nrgWmv = function(src,width,height,elementID,mute,autostart){
		setGMStatus("GM Loading");
		window.setTimeout(function() {
	 		GM_xmlhttpRequest({
			  method:"GET",
			  url:src,
			  onload:function(details) {
				if (details.status != 200)
				{
					setGMStatus("GM failed");
					GM_log("Unable to load video: " + src, 2);
				}
				else
				{
					var videoUrl = src;
					var allTags = details.responseText.match(/<[^>]+>/g);
					var i, l = allTags.length;
					var inEntry = false;
					var canSkip = true;
					var tagName;
					for (i = 0; i < l; i++)
					{
						tagName = allTags[i].match(/[a-zA-Z]+/);
						if (tagName != null)
						{
							tagName = tagName[0].toLowerCase();
							switch (tagName)
							{
							case "entry":
								if (!inEntry)
								{
									inEntry = true;
									canSkip = true;
								}
								else
									inEntry = false;
								break;
							case "param":
								paramName = allTags[i].match(/name[ ]*=[ ]*"[^"]+"/i);
								paramValue = allTags[i].match(/value[ ]*=[ ]*"[^"]+"/i);
								if (paramValue != null && paramName != null)
								{
									paramName = paramName[0].replace(/^.*"([^"]+)".*$/, "$1").toLowerCase();
									paramValue = paramValue[0].replace(/^.*"([^"]+)".*$/, "$1").toLowerCase();
									if (paramName == "canseek" && paramValue == "no")
										canSkip = false;
								}
								break;
							case "ref":
								if (canSkip) 
								{
									var href = allTags[i].match(/href[ ]*=[ ]*"[^"]+"/i);
									if (href != null)
									{
										videoUrl = href[0].replace(/^.*"([^"]+)".*$/, "$1");
										http2mms(elementID, videoUrl, width, height);
										return;
									}
								}
								break;
									
							}
						}
						
					}	
					document.getElementById(elementID).innerHTML = getPlayerHtml(videoUrl, width*1.2, height*1.2);
				}
			  }
			});
		}, 0);
	}
	var underVid = document.getElementById("videoText");
	if (underVid != null)
	{
		underVid.childNodes[0].innerHTML = "<span style=\"float:left\" id=\"GMStatus\">GM OK</span>" +
			underVid.childNodes[0].innerHTML;
	}
}
if (window.location.href.match(/nrg.co.il\//i))
{
	fixFlash();
	fixVideo();
}