Cp-s05box Wiki
(based on regex)
Line 36: Line 36:
 
"whore",
 
"whore",
 
"whores"
 
"whores"
 
 
],
 
],
 
c = false; // prevent duplication if blocked word was detected already
 
c = false; // prevent duplication if blocked word was detected already
for (var i = 0; i < b.length; i++) {
+
for (var i = 0; i < b.length; i++) { // loop through all words
 
var d = b[i];
 
var d = b[i];
 
if (
 
if (
 
(
 
(
 
/* possibilities start */
 
/* possibilities start */
  +
a == d || // whole message equals the word
a == d ||
 
a.indexOf(d + " ") == 0 ||
+
a.search(new RegExp(d + "[ ,\\.\\!\\?]")) == 0 || // starts with the word
  +
a.search(new RegExp("[ ,\\.\\!\\?]" + d + "[ ,\\.\\!\\?]")) > -1 || // contains the word
a.indexOf(d + ",") == 0 ||
 
 
a.substr(a.length - d.length - 1).search(new RegExp("[ ,\\.\\!\\?]" + d)) > -1 // end with the word
a.indexOf(d + ".") == 0 ||
 
a.indexOf(d + "!") == 0 ||
 
a.indexOf(d + "?") == 0 ||
 
a.indexOf(" " + d + " ") > -1 ||
 
a.indexOf(" " + d + ",") > -1 ||
 
a.indexOf(" " + d + ".") > -1 ||
 
a.indexOf(" " + d + "!") > -1 ||
 
a.indexOf(" " + d + "?") > -1 ||
 
a.indexOf("," + d + " ") > -1 ||
 
a.indexOf("," + d + ",") > -1 ||
 
a.indexOf("," + d + ".") > -1 ||
 
a.indexOf("," + d + "!") > -1 ||
 
a.indexOf("," + d + "?") > -1 ||
 
a.indexOf("." + d + " ") > -1 ||
 
a.indexOf("." + d + ",") > -1 ||
 
a.indexOf("." + d + ".") > -1 ||
 
a.indexOf("." + d + "!") > -1 ||
 
a.indexOf("." + d + "?") > -1 ||
 
a.indexOf("!" + d + " ") > -1 ||
 
a.indexOf("!" + d + ",") > -1 ||
 
a.indexOf("!" + d + ".") > -1 ||
 
a.indexOf("!" + d + "!") > -1 ||
 
a.indexOf("!" + d + "?") > -1 ||
 
a.indexOf("?" + d + " ") > -1 ||
 
a.indexOf("?" + d + ",") > -1 ||
 
a.indexOf("?" + d + ".") > -1 ||
 
a.indexOf("?" + d + "!") > -1 ||
 
a.indexOf("?" + d + "?") > -1 ||
 
a.substr(a.length - d.length - 1) == " " + d ||
 
a.substr(a.length - d.length - 1) == "," + d ||
 
a.substr(a.length - d.length - 1) == "." + d ||
 
a.substr(a.length - d.length - 1) == "!" + d ||
 
a.substr(a.length - d.length - 1) == "?" + d
 
 
/* possibilities end */
 
/* possibilities end */
 
) && c === false
 
) && c === false

Revision as of 15:04, 3 February 2014

//

/*
	the following script blocks certain works in certain conditions
*/

ChatStringsBlocker = {"count": 0};
$('textarea[name="message"]').on("keypress", function(e) {
	if (e.keyCode == 13) {
		var a = $('textarea[name="message"]').val().toLowerCase(),
			b = [
				"ass",
				"asses",
				"bitch",
				"bitches",
				"bitchy",
				"boob",
				"boobs",
				"cunt",
				"dick",
				"fuck",
				"fucker",
				"fucking",
				"motherfucker",
				"nigga",
				"niggas",
				"nigger",
				"niggers",
				"penis",
				"penises",
				"piss",
				"pussy",
				"shit",
				"shitty",
				"tits",
				"sex",
				"whore",
				"whores"
			],
			c = false; // prevent duplication if blocked word was detected already
		for (var i = 0; i < b.length; i++) { // loop through all words
			var d = b[i];
			if (
			(
			/* possibilities start */
				a == d ||                                                                      // whole message equals the word
				a.search(new RegExp(d + "[ ,\\.\\!\\?]")) == 0 ||                              // starts with the word
				a.search(new RegExp("[ ,\\.\\!\\?]" + d + "[ ,\\.\\!\\?]")) > -1 ||            // contains the word
				a.substr(a.length - d.length - 1).search(new RegExp("[ ,\\.\\!\\?]" + d)) > -1 // end with the word
			/* possibilities end */
			) && c === false
			) {
				var c = true;
				$('textarea[name="message"]').val("");
				ChatStringsBlocker.count++;
				if (ChatStringsBlocker.count < 2) {
					alert("Warning! You were caught using innapropriate language and your message has been blocked.");
				} else if (ChatStringsBlocker.count === 2) {
					alert("LAST WARNING!!!\nIt's the second time you were caught using inappropriate language. A third time would auotmatically kick you from the chat room!");
				} else if (ChatStringsBlocker.count === 3) {
					window.close(); // close on 3rd offense
				}
			}
		}
	}
});

//