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

Adding a simple blacklist filter #2

Open
lazymanc opened this issue Dec 19, 2011 · 2 comments
Open

Adding a simple blacklist filter #2

lazymanc opened this issue Dec 19, 2011 · 2 comments

Comments

@lazymanc
Copy link

Here's a quick example of how to stop tweets containing particular words from displaying.

$("#tweets").jTweetsAnywhere({
  blacklist    : [
    "badWord1",
    "badWord2",
    "badWord3",
    "etc"
  ],
  tweetFilter: function(tweet, options) {
    var blacklistCount = options.blacklist.length;

    if(blacklistCount < 1) {
      return true;
    }

    for(var i = 0; i < blacklistCount; i++) {
      var regex = new RegExp(options.blacklist[i], "gi");

      if(tweet.from_user.search(regex) != -1 || tweet.text.search(regex) != -1) {
        return false;
      }
    }

    return true;
  }
});

Not sure if this is the right place to post it, but hopefully it'll come in handy for someone.

@tbillenstein
Copy link
Owner

Thanks Phil for the sample.

Filtering tweets is one of the things people ask a lot about. I already thought about extending the current tweetFilter functionality because for a lot (non-programmer) users filling a white-/blacklist is much easier than coding a tweetFilter function.

@lazymanc
Copy link
Author

It's difficult to judge what should be part of the plugin - you don't want it to become too bloated and heavy. The plugin is easily extendible though which is probably better than having lots of in-built features.

Maybe rather than including additional filters, you could have a page in the docs with common solutions such as whitelist / blacklist example code? That way you keep the plugin lightweight but still give people easy access to extra features that they can pick and choose from.

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

No branches or pull requests

2 participants