// ==UserScript==
// @name Ignore people on Planet
// @author Faux
// @namespace http://faux.uwcs.co.uk/
// @version 0.21
// @description Adds ignore buttons to planet that collapse the user in question's posts.
// add excluded sites here (if the script causes problems on those sites)
// @exclude http://www.some.example.com/*
// @include http://planet.uwcs.co.uk/*
// ==/UserScript==

var prefix = 'zomgfauxplanet';

var trackedelems /*Nick => (index => element)*/ = Array();
var checkboxclones /*Nick => (index => element)*/ = Array();

// On load, add all the buttons.
window.opera.addEventListener('BeforeEvent.load',function (e)
{
	if( e.event.target instanceof Document )
	{
		var eders = document.getElementsByTagName('h3');
		var ael,count=0;
		for (var i=0; i<eders.length; i++)
			// ignore planet lameness
			if (ael = eders[i].getElementsByTagName('a')[0])
			{
				// Add the button.
				var uname = ael.innerHTML;
				var elname = prefix + (++count);
				eders[i].innerHTML =
				'<span style="font-size: 50%"><label for="' + elname + '">' +
				'[ <input ' +
				'id="' + elname + '" ' +
				'type="checkbox" ' +
				'onclick="removeall(this, \'' + uname + '\');"/> ' +
				' ignore ]' +
				'</label> </span>' +
				eders[i].innerHTML;

				// Skip the text and get to the div|the image.
				var diviq = eders[i].nextSibling.nextSibling;

				// If it's the image..
				if (diviq.className == "face")
					// Skip the text and on to the div.
					diviq = diviq.nextSibling.nextSibling;

				// Ensure our map exists.
				if (!trackedelems[uname])
					trackedelems[uname] = Array();

				// Ensure our other map exists.
				if (!checkboxclones[uname])
					checkboxclones[uname] = Array();

				checkboxclones[uname][checkboxclones[uname].length] = eders[i].firstChild.firstChild.firstChild.nextSibling;

				// Save this div.
				trackedelems[uname][trackedelems[uname].length] = diviq;

				// Save any proceeding ones with the right classname.
				while ((diviq = diviq.nextSibling.nextSibling) && diviq.className == "entrygroup")
					trackedelems[uname][trackedelems[uname].length] = diviq;
			}
	}
}, false);

// Hide the divs associated with this nick.
function removeall(what, a)
{
	var p = checkboxclones[a];

	for (var i = 0; i < p.length; ++i)
		p[i].checked = what.checked;

	var q = trackedelems[a];

	for (var g = 0; g < q.length; ++g)
		q[g].style.display = what.checked ? "none" : "";

}
