Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-29-2012, 07:20 AM   PM User | #1
Sumaheris
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sumaheris is an unknown quantity at this point
Thumbs up How to mask unwanted words in site?

I know a little bit of JS Codding but I have no idea how to mask words or numbers for selected site? For www.examplecode.exm
Containing words: sh*t or pe*. I don't want see those words. How can I make .js file which changes those words into for ex. Flower and water? Or 100 into 50? They won't change sites content but only my clientside browser's perception to those words!

I just need some ideas and suggestions?
Sumaheris is offline   Reply With Quote
Old 09-29-2012, 07:38 AM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Try this SmutEngine:-

Code:
<html>
<head>

<script type="text/javascript">

var notAllowed = [["*"], [" sex"], [" rape"], ["damn"], [" ***]", ["arse"], ["porn"], ["intercourse"], ["erotic"], ["pervert"]];

// Filters sex but not Essex, filters rape but not drape, filters a*s*s (blocked on this site!) but not pass
// But then kinkysex, gangrape and fatass are not blocked.  You can't win!

	
function checkWord(txt){
txt = " " + txt.value;  // catch initial badwords starting with a space
lctxt = txt.toLowerCase();
for (var i = 0; i < notAllowed.length; i++) {
if (lctxt.indexOf(notAllowed[i]) != -1){
alert ('The word "' + notAllowed[i] + '" is not allowed!');
var rep = txt.substr(0, lctxt.indexOf(notAllowed[i]));
if (notAllowed[i] !="*") {
if (/[^\s]$/.test(rep)) {  // add a space at end of text if not one already
rep = rep + " ";
}
}
rep = rep.replace (/^\s/, "");  // remove initial space again
document.getElementById("myText").value = rep;
return false;
}
}
}

</script>
</head>

<body>

<form name = "myForm">
<textarea name="myText" rows="10" cols="50" onkeyup="checkWord(this)"></textarea>
</form>

</body>
</html>
The advantage is that it is case insensitive and notAllowed words are removed as they are typed, which may help to discourage abusers. This is perhaps better than replacing the badwords by **** which the reader may guess. But as always bad-word or bad word or b.a.d.w.o.r.d will get through.

It is impossible to filter badwords completely. The script will filter for gangrape if the notAllowed word is 'rape' (no leading space) but that will also filter out drape and grape and scrape. I guess that might be accepted as drape, grape and scrape are uncommon words. Likewise kinkysex is filtered out if the notAllowed word is 'sex' (no leading space) but the penalty is that Essex and Sussex are also blocked.

If you mean erase badwords displayed on someone else's site, then that cannot be done. The remedy is obvious - don't visit sites which permit bad language.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 09-29-2012 at 06:10 PM..
Philip M is offline   Reply With Quote
Old 09-29-2012, 07:51 AM   PM User | #3
Sumaheris
New to the CF scene

 
Join Date: Sep 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Sumaheris is an unknown quantity at this point
Thumbs up

Thanks for help!

I didn't said change someone's else site, but only my own browsers reaction to it!

Code:
javascript:document.body.contentEditable='true'; document.designMode='on'; void 0
something like this, but added as addon in the browser somewhere and does job automaticaly.

Thanks!
Sumaheris is offline   Reply With Quote
Old 09-29-2012, 06:10 PM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,100
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
As I say, if you mean erase badwords displayed on someone else's site (viewed in your browser), then that cannot be done.

The reason is the Same Origin Policy. Simply stated, the SOP states that JavaScript code running on a web page may not interact with any resource not originating from the same web site.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.

Last edited by Philip M; 09-29-2012 at 06:28 PM..
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
censored, javascript, kid, mask, word

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 03:13 AM.


Advertisement
Log in to turn off these ads.