Greasemonkey Scriptlet for WordPress Comment Moderation

It’s Spam Season again, apparently. This means lots of annoying spam comments on my blogs and more time than I’d have liked trying to get rid of them. One little nuisance in particular had been a pain in my neck for two days, and yesterday I finally decided to ease the burden.

When WordPress 1.2’s built-in comment moderation system catches comments it thinks are spam, it sends these comments off into the moderation queue. There the comment can be reviewed, and appropriate action (accept the comment, delete the comment, or ignore the comment and leave it in the moderation queue) can be taken. In order to act on multiple comments at a time (since spam travel in packs), a “bulk action” radio button can be pressed for each comment one wants to peform the selected action upon. Trouble is, when there are 229 spam comments in your moderation queue, this means you have to press 229 radio buttons.

There has to be a better way. Enter Greasemonkey, stage left. From its web site:

Greasemonkey is a Firefox extension which lets you to add bits of DHTML (“user scripts”) to any web page to change its behavior. In much the same way that user CSS lets you take control of a web page’s style, user scripts let you easily control any aspect of a web page’s design or interaction.

Long story short, I wrote a tiny Greasemonkey scriptlet called WP-Delete Moderated Comments which will automatically set WordPress’s comment moderation radio buttons to “delete” rather than “do nothing.” As a result, instead of clicking the mouse 229 times, I merely have to click once on the submit button. Here it is:

// ==UserScript==
// @name           WP-Delete Moderated Comments
// @description    Sets all moderated comments caught in WordPress to be deleted. (Tested with WordPress 1.2 Mingus.)
// @author         Meitar Moscovitz ( http://maymay.net/ ) Copyright 2005
// @include        Change this to your WordPress blog's comment moderation page.
// ==/UserScript==

(function () {
    var e = document.getElementsByTagName('input');
    for (var i=0; i<e.length; i++)
    {
        if (e[i].type == 'radio' && e[i].value == 'delete' && e[i].defaultChecked == false)
        {
            e[i].checked = true;
        }
    }
})();

For those of you who already have Greasemonkey installed, you can install WP-Delete Moderated Comments right now. (Right-click on the link and select “Install User Script…” from the contextual menu. Then change the included page to the appropriate address, as instructed.)

Questions, comments, suggestions and any other feedback are all welcome.

Note: This scriptlet only works for WordPress 1.2 Mingus. No future updates are planned because this functionality is already available in the WordPress core for versions 1.5 and greater.

2 comments

Comments are closed.