User:Zombie Maces/censor.js

/** * censor.js * * Censor out various curse words. * * WARNING: This source code contains all of the curse words it censors! * Beware, NSFW! * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * This script is a modification of Gary King's Comments in Local Time * from Wikipedia. $(document).ready(function { var node = document.getElementById('bodyContent'); replace_text(node, /fuck/gi, '****'); replace_text(node, /shit/gi, '****'); replace_text(node, /penis/gi, '*****'); replace_text(node, /vagina/gi, '******'); replace_text(node, /ass/gi, '***'); replace_text(node, /cunt/gi, '****'); replace_text(node, /fag/gi, '***'); replace_text(node, /nigger/gi, '******'); replace_text(node, /gook/gi, '****'); replace_text(node, /bitch/gi, '*****'); function replace_text(node, search, replace) {	if (node.nodeType == 3)	{		var value = node.nodeValue;		var matches = value.match(search);		if (matches != null)		{			var node_parent_node = node.parentNode;			var old_node = node;			// old_node_list = node.parentNode.childNodes;			for (match = 0; match < matches.length; match++)			{				// Create MATCHES[MATCH] var position; if (after_match != null && length != null) position = after_match.search(search) + before_match.length + length; else position = value.search(search); var length = matches[match].toString.length; var before_match = value.substring(0, position); var after_match = value.substring(position + length); var span = document.createElement('span'); /***				 * Replaced text has a span tag, you can manipulate it here. */				span.appendChild(document.createTextNode(matches[match].toString.replace(search, replace))); var new_node = document.createDocumentFragment; new_node.appendChild(document.createTextNode(before_match)); new_node.appendChild(span); new_node.appendChild(document.createTextNode(after_match)); node_parent_node.replaceChild(new_node, old_node); break; }		}	}	else {		var children = [], child = node.firstChild; while (child) {			children[children.length] = child; child = child.nextSibling; }		for (var child = 0; child < children.length; child++) replace_text(children[child], search, replace); } } });