psychoticmeow / Something Awful Auspol Idiot Removal

// ==UserScript==
// @name			Something Awful Auspol Idiot Removal
// @namespace		SA
// @description		Replace the posts of idiots posting in the auspol threads with a random picture of a shitty LNP member.
// @version			1.0.0
// @grant			none
// @icon			http://i.somethingawful.com/images/gren-left-64.png
// ==/UserScript==

"use strict";

var Images = [
	// Bronwyn:
	'2gk0cvL',

	// Christopher:
	'LgoBaHb',
	'0xeYAwD',
	'AXp9dm7',
	'5bh7szl',
	'n3CEs7z',

	// Clive:
	'lLKnI2m',

	// Joe
	'j65cJ2P',
	'LXFIgP5',
	'eXLn5eW',

	// John
	'qtWTuhP',
	'eS12FOd',

	// Julie:
	'h7C1btb',
	'jdJHFjR',
	'E7uKezg',
	'aVf99O1',

	// Tony:
	'KnkWZaO',
	'yS0uA4a'
];

var Users = [
	'Negligent'
];

if (0 <= document.title.indexOf('Auspol')) {
	var posts = document.querySelectorAll('table.post'),
		quotes = document.querySelectorAll('div.bbc-block blockquote');

	// Find posts written by idiots:
	for (var index in posts) {
		var post = posts[index];

		if (!(post instanceof HTMLElement)) continue;

		var author = post.querySelector('td.userinfo dt.author'),
			imageId = Images[index % Images.length],
			image = document.createElement('img');

		image.setAttribute('src', 'http://i.imgur.com/' + imageId + 'l.jpg');

		// Found a post written by an idiot:
		if (0 <= Users.indexOf(author.textContent)) {
			var postbody = post.querySelector('td.postbody');

			// Remove all content from the post:
			while (postbody.firstChild) {
				postbody.removeChild(postbody.firstChild);
			}

			// Insert the image:
			postbody.appendChild(image.cloneNode(true));
		}
	}

	// Find quotes of idiots:
	for (var index in quotes) {
		var quote = quotes[index];

		if (!(quote instanceof HTMLElement)) continue;

		var author = quote.parentNode.querySelector('h4 a.quote_link');

		if (!(author instanceof HTMLElement)) continue;

		var imageId = Images[index % Images.length],
			image = document.createElement('img');

		image.setAttribute('src', 'http://i.imgur.com/' + imageId + 'l.jpg');

		if (0 <= Users.indexOf(author.textContent.replace(/ posted:/, ''))) {
			// Remove all content from the post:
			while (quote.firstChild) {
				quote.removeChild(quote.firstChild);
			}

			// Insert the image:
			quote.appendChild(image.cloneNode(true));
		}
	}
}