tbillenstein / jTweetsAnywhere

jTweetsAnywhere is a jQuery Twitter Widget that simplifies the integration of Twitter services into your site
http://thomasbillenstein.com/jTweetsAnywhere/
MIT License
51 stars 18 forks source link

Adding a simple blacklist filter #2

Open lazymanc opened 12 years ago

lazymanc commented 12 years ago

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 commented 12 years ago

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 commented 12 years ago

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.