Troll Killer Greasemonkey Script - updated to support FF3

UHE is now closed. For Technical Support from Ableton, please go here: http://www.ableton.com/support
Locked
Angstrom
Posts: 14713
Joined: Mon Oct 04, 2004 2:22 pm
Contact:

Troll Killer Greasemonkey Script - updated to support FF3

Post by Angstrom » Thu Nov 18, 2010 1:53 am

Hi all,
I'm not sure how many people are interested in this, but if you want to hide certain users on forums such as this one there is a script (below) which you can use with Firefox, and a plugin called Greasemonkey.

It's working fine for me on FF3, and should for you too.
Users now have an [X] next to their name, click it and their posts become just a pale name, you can click them again if you ever want to bring them back from your personal hell.


For the moment I've no real time to add instructions. I guess the standard methods for installing a greasemonkey script will do you. It has a few flaws at the moment because I had to go and pull some code from other people's versions of this to get it working with Firefox 3, the old version was FF2 only. They changed the XPATH evaluate code for FF3. Anyway. here's the script

Code: Select all

// ==UserScript==
// @name         phpBB User Hide 
// @include      */viewtopic.php*
// @description  Hide posts of the selected users on any phpBB system for Firefox 3.x  Usage: On topic view an[X] appears before every username. Click it to hide the selected user. 
// @exclude
// ==/UserScript==

(function(){
	// Get stored hidden users from cookie
	var users = [];
	var cookieName = "phpUserHide";
	for (var i = 0; i < document.cookie.split('; ').length; i++) {
		var oneCookie = document.cookie.split('; ')[i].split('=');
		if (oneCookie[0] == cookieName) {
			users = oneCookie[1].split(', ');
			break;
		}
	}

	// Cursor functions
	var curPointer = function(event) {
		event.target.style.cursor = 'pointer';
		event.preventDefault();
	};
	var curDefault = function(event) {
		event.target.style.cursor = 'default';
		event.preventDefault();
	};

	// Add or remove a user from the cookie
	var addRemoveUser = function(event) {
		// Parse current cookie
		for(j = 0; j < document.cookie.split('; ').length; j++ ) {
			var oneCookie = document.cookie.split('; ')[j].split('=');
			if (oneCookie[0] == cookieName) {
				users = oneCookie[1].split(', ');
				break;
			}
		}
		var user = escape(event.target.nextSibling.innerHTML)
		notFound = true;
		for (var j = 0; j < users.length; j++) {
			if (users[j] == user) {
				users.splice(j, 1);
				notFound = false;
			}
		}
		if (notFound)users.push(user);
		if (users.length > 0) {
			var date = new Date();
			var days = 365;
			date.setTime(date.getTime() + (days*24*60*60*1000));
			var expires = '; expires=' + date.toGMTString();
			var value = users.join(', ');
			document.cookie = cookieName + '=' + value + expires + '; path=/';
		} else {
			document.cookie = cookieName + '=;expires=Thu, 01-Jan-1970 00:00:01 GMT; path=/';
		}
		window.alert(unescape(user) + ' has been ' + (notFound ? 'added to' : 'removed from')
			+ ' your hide list.');
		event.preventDefault();

     window.location.reload();
	};
	// Toggle display of user's post
	var togglePost = function(event) {
		var displayState = event.target.getAttribute('displaystate');
		if (displayState == 'none')
			displayState = '';
		else
			displayState = 'none';
		event.target.setAttribute('displaystate', displayState);

		containingRow = event.target.parentNode.parentNode;

		var innerTags = containingRow.getElementsByTagName('*');
		for (var i = 0; i < innerTags.length; i++) {
			var tagClass = innerTags[i].getAttribute('class');
			if (tagClass == 'postbody' || tagClass == 'postsig'
				|| tagClass == 'postdetails' || innerTags[i].tagName == 'TABLE')
				innerTags[i].style.display = displayState;
		}
		event.preventDefault();
	};
	// Toggle display of user's quote
	var toggleQuote = function(event) {
		var displayState = event.target.getAttribute('displaystate');
		if (displayState == 'none'){displayState = 'table-row';}else{displayState = 'none';}
		event.target.setAttribute('displaystate', displayState);

		// Jump to parent row
		var containingRow = event.target.parentNode.parentNode.parentNode.parentNode.nextSibling;
		// Find containing row
		while (containingRow.nodeType != 1)
			containingRow = containingRow.nextSibling;
		containingRow.style.display = displayState;
		event.preventDefault();
	};

	// Find all the usernames in the page

	var results =document.evaluate("//b[@class='postauthor']", document, null,XPathResult.ANY_TYPE, null);
	var resultNodes = [];
	var aResult;
	while (aResult = results.iterateNext()){resultNodes.push(aResult);}
	// Loop through every user post on the page
 
	for (var i in resultNodes) {
		var containingRow = resultNodes[i].parentNode.parentNode.parentNode;
		// Format whitespace
		var user = escape(resultNodes[i].innerHTML);

		// Flag whether the user is in our hide list
		var notFound = true;
		for (var j = 0; j < users.length; j++) {
			if (users[j] == user) {
				notFound = false;
			}
		}

		// Add relevant event handlers to user's name and a toggler node
		var toggler = document.createElement('span');
		toggler.setAttribute('title', "click to add or remove this user from your hide list");
		toggler.appendChild(document.createTextNode('[X] '));
		toggler.style.fontSize = "7pt";
                toggler.style.color = "#777777";
		toggler.addEventListener('mouseover', curPointer, true);
		toggler.addEventListener('mouseout', curDefault, true);
		toggler.addEventListener('click', addRemoveUser, true);

		resultNodes[i].parentNode.insertBefore(toggler, resultNodes[i]);

		// If this user isn't in our hide list, skip to the next user
		if (notFound)continue;

		// Find the first element node (td) in the containing row
		var elem = containingRow.firstChild;
		while (elem.nodeType != 1)
			elem = elem.nextSibling;


		var innerTags = containingRow.getElementsByTagName('*');
		for (var i = 0; i < innerTags.length; i++) {
			var tagClass = innerTags[i].getAttribute('class');
			if (tagClass == 'postbody' || tagClass == 'postsig'
				|| tagClass == 'postdetails' || tagClass == 'roundedbr'|| tagClass == 'profile roundedbl'|| 

innerTags[i].tagName == 'TABLE'){innerTags[i].style.display = 

'none';}else{innerTags[i].style.color="#AAAAAA";innerTags[i].style.background="#FFFFFF";}// look for hide tags, or tint the ones we 

aren't hiding, including making the BG white;
				
		}
	}

	// Find all the usernames quoted in the page
	var results = document.evaluate("//td[@class='quote']/parent::*/preceding-sibling::*/td/span/b|"+ 

"//td[@class='quote']/parent::*/preceding-sibling::*/td/span/strong", document, null,XPathResult.ANY_TYPE, null);
	var resultNodes = [];
	var aResult;
	while (aResult = results.iterateNext())
		resultNodes.push(aResult);

	// Loop through every user quote on the page
	for (var i in resultNodes) {
		var containingRow = resultNodes[i].parentNode.parentNode.parentNode.nextSibling;
		while (containingRow.nodeType != 1)containingRow = containingRow.nextSibling;

		// Find username
		var usermatch = resultNodes[i].innerHTML.match(/(.*) wrote:$/);
		if (usermatch){var user = escape(usermatch[1]);}else{continue;}
			

		// Flag whether the user is in our hide list
		var notFound = true;
		for (var j = 0; j < users.length; j++) {
			if (users[j] == user) {
				notFound = false;
			}
		}

		// If this user isn't in our hide list, skip to the next user
		if (notFound)
			continue;

		// Create a span to control toggling
		var span = document.createElement('span');
		span.appendChild(document.createElement('br'));
		span.appendChild(document.createTextNode('Toggle Display'));
		span.setAttribute('class', 'gensmallbold');
		span.style.textDecoration = 'underline';
		span.setAttribute('displaystate', 'none');
		span.addEventListener('mouseover', curPointer, true);
		span.addEventListener('mouseout', curDefault, true);
		span.addEventListener('click', toggleQuote, true);

		resultNodes[i].appendChild(span);
		
		// Hide the quote
		containingRow.style.display = 'none';
	}

})();

Locked