4chan - Highlight all sage posts

By damantis Last update Jan 14, 2010 — Installed 2,637 times.

There are 9 previous versions of this script.

// ==UserScript==
// @name           4chan - Highlight all sage posts
// @namespace      sage (http://userscripts.org/scripts/show/36554)
// @description    Looks for all mailto:sage hyperlinks and changes them from the default blue colour to red. This is useful as you can distinguish posts with sage in the email field from posts with genuine email addresses. 
// @include        http://*.4chan.org/*
// ==/UserScript==


// Highlight a mailto:sage hyperlink (red + italic).

function highlightLink(l)
{
	l.style.color = "red";
	l.style.fontStyle = "italic";
}

// Read a hyperlink and determine if it contains "mailto:sage" or not.

function readLink(l)
{
	if(l.href.indexOf("mailto:") == 0) {
		var email = l.href.toLowerCase();
		if(email.indexOf("sage") != -1)
			highlightLink(l);
	}
}

// Read whole page on load.

function readDocument()
{
	Array.forEach(document.getElementsByTagName('A'), readLink);
}

readDocument();


/*  Thread Expansion
 *
 *  When the thread expansion feature of the 4chan Firefox extension is used,
 *  the expanded posts have to be highlighted as well.
*/

//  Each expanded post comes in its own <TABLE>.
//  This function searches for all hyperlinks in a <TABLE>.

function searchNewPosts(e)
{
	if(e.target.nodeName=="TABLE")
		Array.forEach(e.target.getElementsByTagName('A'), readLink)
}

//  When the page is expanded, search for new hyperlinks.

if(form = document.evaluate("child::form", document.body, null, 8, null).singleNodeValue)
	form.addEventListener("DOMNodeInserted", searchNewPosts, true );
delete form;