Stop Twitter Spammers with this Greasemonkey script

In February I wrote about people who follow you on Twitter for no good reason. Since then I’ve probably received a few dozen more requests from entirely random people/bots/MakeMoneyFasts, and while it doesn’t really mean anything, I find it irksome. Others do too – searching tweetscan for block always produces lots of annoyed people.

Blocking someone, though, is a huge pain. You get the mail message which links to the person, then you have to go to Twitter, go to your follower list, page through it to find that person, and then block. Satisfying, but tiresome.

So today I whipped up a Greasemonkey script to help. (You can stop reading and just download it now if you want.) If you’re a Gmail or Google Apps Mail user, and you receive a mail announcing yet another spammer, you can block them in just two clicks: the first goes to a block page, then you confirm. (There’s no way I’ve found to do it in one click yet.)

Here’s what your mail will look like – note the Block!:

Gmail image with Twitter Block link

Easy to do and satisfying.

You can find the script at this link at userscripts.org. Let me know if you have any problems with it.

Some random development notes:

  • This took me about 2.5 hrs, 80% of which was spent learning Greasemonkey, the Gmail Greasemonkey API, and how to do regex replacements in Javascript. I expect doing this for just the Twitter page would take ~30min (so you click through, see that you really don’t know this person, and then block); other mail clients would be fast too, so let me know if you want one.
  • The Gmail Greasemonkey API is a nice touch, esp. because I don’t think you can find the body of a message with XPath otherwise (maybe XPath craps out at a certain # of levels, and the body of the message is 20+ levels deep). However, once you use the API, all document.* functions (including XPath ones) seem to be unavailable: maybe unsafeWindow blocks them, or maybe I just had bad luck.
  • The Dive Into Greasemonkey tutorial might be out of date, but it was still insanely valuable (even if it’s obsessed with timers for some reason).

Enjoy!

Advertisements

2 Responses to “Stop Twitter Spammers with this Greasemonkey script”

  1. tODD Says:

    I’m sure you’re happy with your almost-one-click solution (and you should be!), so this may not matter to you, but the process to block a spammy follower does not need to be as long as you say.

    Once you get your email from Twitter that someone is following you, you can then click on the URL to go to their account (I usually want to do this anyway to evaluate if the account is spammy, based on the URL in the bio and the content of the tweets; it is often not obvious based on the Twitter username). Once there, if you think it’s spammy, you can click on “block username“, which appears in the right-hand box, underneath the “Following” icons (assuming you’re logged in with a cookie). Saves a few steps from the process you’d outlined.

    But either way, kudos for learning Greasemonkey to solve an annoying problem!

  2. Scott Ruthfield Says:

    Wow, I’ve literally never seen that link before. I have no idea why an action is at the bottom of a navigation section, rather than being next to Follow/Following/etc.

    So yeah, that does seem like a bit of a waste of my time. In fact, I was going to add a link to the top of the page because I didn’t even think there was one. Oh well!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: