Xanga Swear Filter
8
This is a swear filter script I wrote for my xanga blog. I don't know if it has any application anywhere else. This will replace the swear words listed in the array with the character defined in blank_char. This isn't perfect but it works pretty well.
<script language="javascript">
var divs = document.getElementsByTagName("div");
var blank_char = "*"; // change this to whatever you want swears words to be blocked out with
var swear_words = new Array("damn", "shit"); // put words you want to be blocked into this array
for (var l = 0; l < divs.length; l++) {
str = divs[l].innerHTML;
for (var i = 0; i < swear_words.length; i++){
rExp = new RegExp(swear_words[i], "i");
if ( str.match(rExp) ) divs[l].innerHTML = str.replace (rExp, repeat(swear_words[i].length, blank_char));
}
}
function repeat(n, b_chr){
// there is probably a better way to do this, but I'm not that good at JavaScript so if you figure something out feel free to revise
var new_text = "";
for (var e = 0; e < n; e++)
new_text = new_text + b_chr;
return new_text;
}
</script>






At least you're not writing user authentication in JS! Oy ve! I've seen people do it, though . . . *grin*
I've got good news, and I've got bad news:
The universe is merely a figment of my imagination.
Now are you ready for the bad news?