Ynet video for mac

By Yehuda B. Last update Oct 13, 2008 — Installed 9,295 times. Daily Installs: 3, 3, 1, 1, 4, 11, 8, 4, 0, 4, 3, 3, 2, 5, 4, 2, 1, 0, 1, 0, 0, 2, 2, 7, 6, 2, 6, 2, 4, 3, 4, 3

There are 3 previous versions of this script.

// Ynet video for mac user script
// version 0.9
// 2008-10-13
// Copyright (c) 2007, 2008 Yehuda B.
// Released under the GPL license
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey/GreaseKit user script.  To install it, you need
// Greasemonkey 0.7.2 or later: http://greasemonkey.mozdev.org/
// Then restart Firefox and revisit this script.
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "ynet video for mac", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          Ynet video for mac
// @namespace     tag:yehudab@gmail.com,2007-01-29:gm
// @description   Allow inline display of Ynet video clips on Mac, Linux and Windows. Version 0.9
// @include       http://players.mediazone.co.il/*
// @include       http://www.ynet.co.il/articles/*
// ==/UserScript==

var isWebKit = RegExp(" AppleWebKit/").test(navigator.userAgent);
function myLog(msg)
{
	if (typeof GM_log == "undefined")
		console.log(msg);
	else
		GM_log(msg);
}

function myXmlhttpRequest(req)
{
	if (typeof GM_xmlhttpRequest == "undefined")
	{
		try {
			var myReq = new XMLHttpRequest();
			myReq.onreadystatechange = 
				function() 
				{
					if (myReq.readyState == 4)
						req.onload(myReq);
				}
			myReq.open(req.method, req.url, true);
			myReq.send("");
		}
		catch (ex)
		{
			alert(ex)
		}
	}
	else
	{
		GM_xmlhttpRequest(req);
	}
}
function fixVideo()
{
	var uWindow;
	if (typeof unsafeWindow == "undefined")
		uWindow = window;
	else
		uWindow = unsafeWindow;
//	uWindow.doPlayerInit = function(){}
	uWindow.preparePlayerCheckPointContextMenu = function(){}
	var dns = document.getElementById("divNotSupported");
	var sts = document.getElementById("bptext");
	var a = document.getElementById("aClip");
	var b = document.getElementById("imgBtnPlayState");
	var spnPreview = document.getElementById("spnPreview");
	var tdPlayerContainer = document.getElementById("tdPlayerContainer");
	var spnPlayerContainer = document.getElementById("spnPlayerContainer");
	var aref = "";
	var failed = false;
	var playing = false;
	if (dns != null) 
		dns.style.visibility="hidden";
	var re =  /playlists\/([0-9]+)\/players.*$/;
	if (window.location.href.match(re))
		aref = window.location.href.replace(re, "playlists/$1/$1_static.asx");
	var isSE = /players\/55\//.test(window.location.href);

	if (aref != ""){
		var asxSrc = aref;
		if (asxSrc.match(/\/players\/[0-9]+_static\.asx/))
		{
			asxSrc = asxSrc.replace("/players/", "/");
			myLog("fixed")
		}
		myXmlhttpRequest(
		{
			method:"GET",
			url:asxSrc,
			onload:function(details) 
			{
				var width = 320;
				var height = 240;
				if (details.status != 200)
				{
					myLog("Unable to load video " + details.status, 2);
					if (sts != null)
					{
						sts.innerHTML = "GM " + details.status;
					}
				}
				else
				{
					var content = details.responseText.substr(details.responseText.indexOf("<ENTRY CLIENTSKIP=\"YES\">"));
					var mmsArr = content.match(/mms:\/\/[^"]*/g);
					var playing = false;
					if (mmsArr != null) 
					{
						var f = function()
						{
							playing = true;
							if (sts != null)
							{
								sts.innerHTML = "GM Loading...";
							}
							var videoUrl = mmsArr[mmsArr.length-1];
							tdPlayerContainer.innerHTML = "<EMBED type='application/x-mplayer2' id='mediaPlayer' width='" + width + "' height='" + height + "' " +
								"src='" + videoUrl + "' autostart='1' showcontrols='1' loop='0'></EMBED>"
						}
						var f2 = function()
						{
							if (!playing)
							{
								f();
							}
						}
						if (isWebKit)
						{
							f();
						}
						else
						{
							if (b != null)
							{
								b.addEventListener('click', f, false);
								b.src = b.src.replace("Playing", "StoppedPaused");
							}
							if (spnPreview != null)
							{
								spnPreview.addEventListener('click', f2, false);
								spnPreview.style.display="block";
								spnPreview.style.top="";
								var width = Math.max(spnPreview.offsetWidth, 320);
								var height = Math.max(spnPreview.offsetHeight, 240);
							}
							if (spnPlayerContainer != null && isSE)
							{
								spnPlayerContainer.style.display="none";
							}
							
							if (tdPlayerContainer != null)
							{
								tdPlayerContainer.addEventListener('click', f2, false);
							}
						}
					}
					else
					{
						myLog("GM no MMS")
						if (sts != null)
						{
							sts.innerHTML = "GM no MMS";
						}
					}
				}
			}
		});
	}
	else 
	{
		failed = true;
	}
	if (sts != null)
	{
		if (!failed)
		{
			sts.innerHTML = "GM OK";
		}	
		else
		{
			sts.innerHTML = "GM Failed";
		}
	}	
	else if (failed)
	{
		myLog("Unable to patch video page");
	}
}

function fixArticle()
{
	var allFrames = document.getElementsByTagName("IFRAME");
	for (var i = 0; i < allFrames.length; i++)
	{
		var src = allFrames[i].src;
		if (src.match(/http\:\/\/players\.mediazone\.co\.il/))
		{
			var videoId = src.replace(/^.*\/playlists\/([0-9]+)\/players.*$/, "$1");
			var playerId = src.replace(/^.*\/players\/([0-9]+).*$/, "$1");
			var authors = src.replace(/^.*\/authors\/([0-9]+)\/playlists.*$/, "$1");
			var width = allFrames[i].width;
			var height = allFrames[i].height;
			var h = "<div style=\"width:"+ width +"px;height:" + height + "px;" + 
				"background-image:url(http://players.mediazone.co.il/mediazone/pub/authors/" + authors + "/players/"+ playerId + "/images/main.png);" +
				"background-repeat:no-repeat\"><a target=\"_blank\" style=\"target-new:tab;width:320px;height:240px;position:relative;right:" + ((width-320)/2) + "px;top:18px\" href=\"" + src + 
				"\"><img border=\"0\" src=\"http://cm.mediazone.co.il/mediazone/images/authors/" + authors + "/" + 
				videoId + "_r320x240.jpg\" /></a>";
			allFrames[i].parentNode.innerHTML = h;
			break;
		}
	}
}
if (window.location.href.match(/http\:\/\/players\.mediazone\.co\.il/))
	fixVideo();
else if (isWebKit && window.location.href.match(/http\:\/\/www\.ynet\.co\.il/))
	fixArticle();