Twitter Filter

By Barry Hess Last update Nov 4, 2008 — Installed 3,953 times.

block username?

in
Subscribe to block username? 3 posts, 3 voices



dsjkvf Scriptwright

is it possible to block a username? it seems I only succeed to filter a certain word, not a user.

 
Jeff MacMichael User

Awesome, Barry - just was I was looking for.

@dsjkvf - to block a username, add this to the end of function filter_tweets:
// Filter by tweet author
$('.screen-name').each(function() {
inner = this.innerHTML;
if((null == whitelist_regex) || (null == inner.match(whitelist_regex)))
if(inner.match(blacklist_regex))
$(this).parents('.hentry.status').hide();
});

It's the same as the content search, but on screen name. There's undoubtedly a more elegant way to do this, but I don't think it breaks the logic.

 
Piroghi User
X11

Using Jeff's idea I modified the filter_tweets function so that a user's tweets are filtered if the screen-name matches the blacklist except when the particular tweet matches whitelist (please don't judge my js too harshly cos I don't know any :)

(You may want to change the titles of the filters a bit on the page too)

function filter_tweets(_whitelist, _blacklist) {
whitelist = _whitelist || readCookie('gmscript_filter_whitelist') || '';
blacklist = _blacklist || readCookie('gmscript_filter_blacklist') || '';
whitelist = ('null' == whitelist) ? '' : whitelist;
blacklist = ('null' == blacklist) ? '' : blacklist;
whitelist_regex = ('' == whitelist) ? null : new RegExp(whitelist, 'i');
blacklist_regex = ('' == blacklist) ? null : new RegExp(blacklist, 'i');

//$('.entry-content').each(function() {
// inner = this.innerHTML;
// if((null == whitelist_regex) || (null == inner.match(whitelist_regex)))
// if(inner.match(blacklist_regex))
// $(this).parents('.hentry.status').hide();
//});

// Filter by tweet screen-name but still have whitelist act on entry-content
$('.status-body').each(function() {
screen_name = this.getElementsByClassName('screen-name')[0].innerHTML;
entry_content = this.getElementsByClassName('entry-content')[0].innerHTML;
if((null == whitelist_regex) || (null == entry_content.match(whitelist_regex)))
if(screen_name.match(blacklist_regex))
$(this).parents('.hentry.status').hide();
});
}