// ==UserScript==
// @name          blacklist
// @description   hide posts from blacklisted users
// @include       http://www.em411.com*
// @include	  http://em411.com*
// ==/UserScript==

var blackList=new Array('aggrouser','trolluser','arsehat','fucktard');

var allDivs, thisDiv;
allDivs = document.evaluate(
    "//div[@class='post']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
for (var i = 0; i < allDivs.snapshotLength; i++) {
    thisDiv = allDivs.snapshotItem(i);
	postauthor=thisDiv.childNodes[1].innerHTML.toLowerCase();
	posttext=thisDiv.childNodes[3].firstChild.innerHTML.toLowerCase();
    for (b in blackList){
	regex=new RegExp(blackList[b].toLowerCase());
		if(postauthor.search(regex)!=-1 || posttext.search(regex)!=-1){
			// zap the 'a' anchor before the post div
			thisDiv.parentNode.removeChild(thisDiv.previousSibling.previousSibling);
			// smash the 'br' affer the post div
			thisDiv.parentNode.removeChild(thisDiv.nextSibling.nextSibling);
			// remove the post div itself
			thisDiv.parentNode.removeChild(thisDiv);
		}
	}
}


// Remove from 'latest posts' section
allDivs = document.evaluate(
    "//div[@class='small sep normal']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
for (var i = 0; i < allDivs.snapshotLength; i++) {
    thisDiv = allDivs.snapshotItem(i);
    for (b in blackList){
		if(thisDiv.childNodes[1].innerHTML.match('<span class="rf">'+blackList[b]+'</span>')){
			// remove the div
			thisDiv.parentNode.removeChild(thisDiv);
		}
	}
}

// Remove from homepage releases
allDivs = document.evaluate(
    "//div[@class='sideReleaseBox']",
    document,
    null,
    XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE,
    null);
for (var i = 0; i < allDivs.snapshotLength; i++) {
    thisDiv = allDivs.snapshotItem(i);
    for (b in blackList){
		if(thisDiv.childNodes[1].innerHTML.match(blackList[b])){
		    // zap the 'a' containing the release div
			thisDiv.parentNode.parentNode.removeChild(thisDiv.parentNode);
		}
	}
}