Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Random word replacement #3

Closed

Conversation

ferventcoder
Copy link

This adds the ability to use random word replacement against a set of swear words. If you don't want it to be random, just provide one word.

This adds to the fun by taking the bad words and cleaning them up into more fun words!

<div id="four" class="example box">
  Often when I go to the bathroom, shit comes out of my arse.
</div>
$('#four').profanityFilter({
    replaceWith:[
      'pretty flower',
      'rainbows',
      'bob',
      'timmy',
      'pony'
      ],
    externalSwears: '/profanity/swearWords.json',
    repeat: false
})

Could result in:

<div id="four" class="example box">
  Often when I go to the bathroom, bob comes out of my rainbows.
</div>

@jpoehls
Copy link

jpoehls commented Jul 11, 2012

This is awesome!

@ChaseFlorell
Copy link
Owner

I'm going to take a look at this over the weekend. Thanks for the PR

//set it back to zero
randomNumber = 0;
}

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well it looks like I forgot to actually set the random number to the last selected random number before returning. Looking at this today this could likely be cleaned up a little.

@jpoehls
Copy link

jpoehls commented Jul 12, 2012

@ferventcoder You might update this to use https://github.com/jpoehls/node-randomSelection (or at least the logic from it) so that the replacement words are randomly used without being repeated more times than is necessary.

@ChaseFlorell
Copy link
Owner

I still haven't had a chance to check this out, but I "will" get to it.

@ferventcoder
Copy link
Author

It's all good (I'm slow at getting to pull requests most of the time). Here's the fix I was looking to get in.

@ChaseFlorell
Copy link
Owner

Took a quick look at this. I think "repeat" needs to be a more descriptive variable name. I already have a repeat prototype, and it "could" be confusing.

Might also want to enable externalClean so that clean phrases can be moved out of the method and cached by the browser.

I might tinker a little... but overall, it's good.

@ferventcoder
Copy link
Author

Thanks. Agreed on repeat. :D

@ferventcoder
Copy link
Author

Following back up on this, did you want me to make the changes and update the PR or were you taking it from here? :)

@ChaseFlorell
Copy link
Owner

I finally had an opportunity to test this. It works great with repeat: false but I'm trying to figure out the purpose of repeat: true.

See This Fiddle

edit - hang on, I'm thinking a bit on this.

@ChaseFlorell
Copy link
Owner

Ok, so on further investigation... I "think" I got this.
I think the appropriate response here is to do type checking.

If replaceWith is an array, then repeat is automatically false
If replaceWith is a string, then repeat is automatically true

I still want to change the name from repeat to something a little more meaningful.

I think I'm gonna work on this tonight a bit and see what I come up with.

@ferventcoder
Copy link
Author

Awesome!

@ChaseFlorell
Copy link
Owner

Ok, so I didn't merge the pull request, but I took your concept and enhanced it a bit. I basically removed the "repeat" and did some type checking.

Take a look and see what you think.

@ferventcoder
Copy link
Author

Looks good to me. :D

Glad to see this feature make it in. Now if you could just support regexes, this would be awesome! ;)

@ChaseFlorell
Copy link
Owner

The next step is going to enable l33k speak.

The concept I'm going to try is to take the basic list of phrases here is a good one for example and then run them through a regex replacing things like "e" with "3" and adding the new variations on the words to the array stored in localStorage.

I really want to avoid running any phrases through a regex every time the method is called, since it's going to slow everything down dramatically.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants