Perl programmer for hire: download my resume (PDF).
John Bokma Greasemonkey
freelance Perl programmer

Digg garbage filter

No more Digg++ | 0 comments

If you read Digg.com often, and like me, get annoyed by people who think readers are really interested that they dugg the article, or that it's lame, install this (experimental) Greasemonkey program.

For more information on installing a JavaScript program into Greasemonkey for Mozilla Firefox, see Link highlighter script for a step-by-step guide.

// ==UserScript==
// @name        Digg Garbage Filter
// @namespace   http://johnbokma.com/firefox/greasemonkey/
// @description Removes useless comments from Digg.com
// @include     http://digg.com*
// @include     http://www.digg.com*
// @exclude
// ==/UserScript==
//
// $Id$ 

var score;
var factor;
var text;

var div;
var divs = document.getElementsByTagName( 'div' );

for ( var i = 0; i < divs.length; i++ ) {

    div = divs[ i ];
    if ( div.className != "comment-body" ) continue;

    text = div.innerHTML.toLowerCase();
    if ( text.length > 60) continue;

    score = 0;
    factor = 1.0;

    if ( text.length < 50 ) factor = 1.1;
    if ( text.length < 40 ) factor = 1.5;
    if ( text.length < 30 ) factor = 1.7;

    if ( text.length < 40 ) score = 1.4;
    if ( text.length < 20 ) score = 2.5;
    if ( text.length < 15 ) score = 3.0;

    if ( text.indexOf( "digg"   ) >= 0 ) score += 3;
    if ( text.indexOf( "dugg"   ) >= 0 ) score += 3;
    if ( text.indexOf( "suck"   ) >= 0 ) score += 3;
    if ( text.indexOf( "great"  ) >= 0 ) score += 1;
    if ( text.indexOf( "old"    ) >= 0 ) score += 1;
    if ( text.indexOf( "crap"   ) >= 0 ) score += 2;
    if ( text.indexOf( "lol"    ) >= 0 ) score += 2;
    if ( text.indexOf( "dupe"   ) >= 0 ) score += 4;
    if ( text.indexOf( "repost" ) >= 0 ) score += 3;
    if ( text.indexOf( "lame"   ) >= 0 ) score += 4;

    if ( score * factor > 5 ) {

        //div.style.backgroundColor = "#ff0000";
        div.parentNode.style.display = "none";
    }

    // add debug info to the original comment
    div.innerHTML += " <strong>["
        + score + ", " + factor + ", "
        + Math.round( 10 * factor * score ) / 10
        + "]</strong>";
}

How the JavaScript program works

The program looks at each div element, and if such an element has a value of "comment-body" assigned to the class attribute, it checks the content of the div element. The JavaScript program uses a score and a factor, the shorter the actual content, the higher the factor. If the score multiplied with the factor is higher then a given threshold, the parent of the div element's display style is set to none, meaning you don't see the comment on Digg.

If you want to see what is going to be deleted before you are actually try it for real, or if you want to tweak the Greasemonkey script, comment out (add //) the following line:

div.parentNode.style.display = "none";

and uncomment (remove //) the following line:

//div.style.backgroundColor = "#ff0000";

which sets the background to red of what the JavaScript program considers comments that should not be displayed on Digg.

Note that the program also shows the score, factor, and factor times score, for short comments after the original comment.

Please post a comment | read 0 comments | RSS feed