Monday, March 16, 2009

Highlight your own posts on VBulletin forums

Coloring your own posts is useful, because then you can quickly scan the threads without having to read your own posts.

Here are instructions for Firefox, IE and Opera.

For Firefox install GreaseMonkey (it is also available for IE) first and install this script below. Change the @include lines for the forums you want to enable the highlight. Set the usernames variable to the names you want to enable post coloring. Set the bgcolor variable to the desired background color.

For Opera GreaseMonkey install is not needed, because it has it it built-in. In Tools/Preferences/Advanced/Content/Javascript Options/User Javascript files set the directory where you will put the script and copy the script there. The configuration is the same as above with the only difference you need to set the hosts variable to specifiy the sites where the script is enabled.

Here's the script text. Copy it verbatim:

// ==UserScript==
// @name VBulletin post colorer
// @namespace http://vbulletincolors.com
// @include http://abc.com/*
// @include http://xyz.com/*
// ==/UserScript==


window.addEventListener(
'load',
function (e)
{
var usernames = ["someuser", "someotheruser"];
var bgcolor = "lightgreen";
// no http prefix! should be set only for Opera
var hosts = ["abc.com", "xyz.com"];

if (navigator.userAgent.match("^Opera"))
{
var found = false;

for (var i = 0; i < hosts.length; i++)
if (hosts[i] == window.location.hostname)
{
found = true;
break;
}

if (!found)
return;
}

var nodes = document.getElementsByTagName("td");

for(var i = 0 ; i < nodes.length ; ++i)
{
var node = nodes[i];
var match = node.id.match("^td_post_(.*)");

if (!match)
continue;

var id = match[1];
var div = document.getElementById("postmenu_" + id);
var children = div.childNodes;

for (var j = 0 ; j < children.length ; j++)
{
var child = children[j];

if (child.nodeName == "A" && child.className == "bigusername")
{
var user = child.text;

for (var k = 0 ; k < usernames.length ; k++)
if (user == usernames[k])
{
node.style.backgroundColor = bgcolor;
break;
}
}
}
}

},
false
);