Automate Reddit

By RedditUser Last update Jan 4, 2009 — Installed 56 times.

There are 5 previous versions of this script.

// ==UserScript==
// @name           Automate Reddit
// @namespace      http://reddit.com
// @description    Automates Reddit
// @include        http://reddit.com/*
// @include        http://*.reddit.com/*
// @exclude        http://reddit.com/user/*
// @exclude        http://*.reddit.com/user/*
// @exclude        http://reddit.com/info/*
// @exclude        http://*.reddit.com/info/*
// ==/UserScript==


// Marks all articles submitted by users who post nothing but crap.
// This match must be complete.
//       i.e. buddy123 != buddy1234
bannedUsers = /IAmperfectlyCalm|georgewashingtonblog|democracy101|MindVirus|rmuser/i;

// Marks and upmods users by name
// This match must be complete.
//       i.e. buddy123 != buddy1234
// supportedUsers = /user_1|user_2|user_3/i;
//
supportedUsers = /reddit-man|leski/i;

// Marks all articles contain the following REGEX downmods in the domain.
bannedDomains = /\.ir<\/a>|factcheck|wecanbelievein|watchingamerica|michaelmoore|DebateTheRace08|voteforamerica|enquirer|talkingpointsmemo|politic|progressive|talkleft|realclearpolitics|foreignaffairs|thinkprogress|huffingtonpost|alternet|allspinzone|dailykos|populist|democracy|crooksandliars|openleft|politico|alcu\.org|andrewsullivan|obama|democrat|impeach|donklephant/i;

// Hide all articles with the following REGEX downmods in the title.
//hiddenWords = /HiddenWord_1|HiddenWord_2/i;
hiddenWords = /NSFW|marijuana|islam|\bjew(s|ish|ed|\b)|Gaza|\bHamas\b|hezbollah|\bArab\w*|Pal[ei]stin\w*|I[sz]r[ae][ae]l| cunt /i;

// Marks all articles that contain the following REGEX downmods
//politicalWords = /BannedWord_1|BannedWord_2|BannedWord_3/i;
politicalWords = /Conservative|liberal|compaign|cand?idate|President|senat[a-zA-Z]*|congress|legislat(e|ion)|(right|left) wing|politic[a-zA-Z]*|\belection|republican|democrat[a-zA-Z]*|O.Rill?y|Limbaugh|palin|bristol|mccain|bush|cheney|karl rove|biden|obama[a-zA-Z]*|barack|\bAyers|rnc|dnc|[^a-zA-Z]?gop |Campaign|ballot|election|impeach/gi;

alwaysDownmoded = /\bvote|Regime|global warming|climate|Environment|9[\/-]?\s?11|Torture|secret prison|Guantanamo|neo.?con|taser|hall?iburton|blackwater|WAKE UP|new world order|Religi\w*|pilgrimage|muslims?|Athei(sm|sts?)|islam|\bjew(s|ish|ed|\b)|Gaza|\bHamas\b|hezbollah|\bArab\w*|Pal[ei]stin\w*|I[sz]r[ae][ae]l|iraq|zion\w*|genocide|war crimes?|suicide bomb(er|ing)|fraud|bail.?out/gi;

var rows;
var downmods=0;
var upmods = 0;
rows = document.evaluate("//*[@class='title']", document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

for (var i = 0; i < rows.snapshotLength; i++) {

    var row = rows.snapshotItem(i);
    var storyID = row.id.substr(9);
    var title = row.childNodes[0].innerHTML;
    var subreddit;
    var Domain = row.getElementsByTagName("span")[0].innerHTML;
    var downmod = /downmod/i;
    var upmod = /upmod/i;

    try {
      subreddit = (document.getElementById('subreddit_'+storyID).innerHTML).toLowerCase();
    }
    catch (err) {
      //GM_log(err.description);
      subreddit = null;
    }
    var user;

    try {
      user = (document.getElementById('author_'+storyID).innerHTML).toLowerCase();
    }
    catch (err) {
      //GM_log(err.description);
      user = null;
    }


    
    if (user && user == bannedUsers.exec(user)) {
        if (!downmod.exec(document.getElementById('down_'+storyID).className) &&
            !upmod.exec(document.getElementById('up_'+storyID).className)) {
            // The following code checks to see if this article has been submitted by an offensive
            // user, and optionally, if the article has been submitted to the proper politics
            // subreddit.  By default, all offensive users are highlighted and downmodded.  Please
            // use this feature sparingly.
            //
            //if (subreddit && subreddit != 'politics') { setTimeout("mod('"+storyID+"',0);",5000); downmods+=1;}
            setTimeout("mod('"+storyID+"',0);",5000); downmods+=1;

            // Highlights the offending article.
            //
            row.parentNode.style.background='lavender';

            user = user.substr(0,1).toUpperCase()+user.substr(1);

            div = document.createElement('div'),
            div.innerHTML = '<p>' + user + ' posts crap.</p> ';
            row.parentNode.insertBefore(div, row.nextSibling.nextSibling.nextSibling);


            // Hides offending article.
            //
            //row.parentNode.parentNode.style.display = 'none';
        }
    }
    else if (user && user == supportedUsers.exec(user)) {
        if (!downmod.exec(document.getElementById('down_'+storyID).className) &&
            !upmod.exec(document.getElementById('up_'+storyID).className)) {
               // upmod the user
               //
               setTimeout("mod('"+storyID+"',1);",5000);

               // highlight entry
               //
               row.parentNode.style.background='#99FF99';
               upmods+=1;

               user = user.substr(0,1).toUpperCase()+user.substr(1);

               div = document.createElement('div'),
               div.innerHTML = '<p>' + user + ' posts good shit.</p> ';
               row.parentNode.insertBefore(div, row.nextSibling.nextSibling.nextSibling);
        }
    }
    else if (thisDomain = bannedDomains.exec(Domain)) {
        if (!downmod.exec(document.getElementById('down_'+storyID).className) &&
            !upmod.exec(document.getElementById('up_'+storyID).className)) {
            // The following code checks to see if the offending domain has been submitted to politics.
            // If it has been properly submitted, the code does not downmod.  If it has not it will
            // be downmoded.  This feature is turned off by defualt.  By default all offending links
            // are downmoded.
            //
            //if (subreddit && subreddit != 'politics') { setTimeout("mod('"+storyID+"',0);",5000); downmods+=1;}
            setTimeout("mod('"+storyID+"',0);",5000); downmods+=1;

            // Highlights the offending article.
            //
            row.parentNode.style.background='LightGoldenRodYellow';

            div = document.createElement('div'),
            div.innerHTML = '<p>' + Domain +' sucks.</p> ';
            row.parentNode.insertBefore(div, row.nextSibling.nextSibling.nextSibling);

            // Hides offending article.
            //
            //row.parentNode.parentNode.style.display = 'none';
        }
    }
    else if (term = politicalWords.exec(title)) {
        if (!downmod.exec(document.getElementById('down_'+storyID).className) &&
            !upmod.exec(document.getElementById('up_'+storyID).className)) {
            // The following code checks to see if the there is an objectionable word in the title
            // of the submitted link.  By default, only political words submitted outside of politics
            // are downmoded and highlighted.
            //
            if (subreddit && subreddit != 'politics') {
               row.parentNode.style.background='MistyRose';
               setTimeout("mod('"+storyID+"',0);",5000); downmods+=1;

               var terms = new Array();
                   count = 0;

               while (term != null)
               {
                 duplicate = false;
                 for (item in terms)
                 {
                   if (terms[item].toUpperCase() == term[0].toUpperCase())
                      duplicate = true;
                   //else
                   //   alert(item + ' ' + term);
                 }

                 if (!duplicate) terms[count++] = term[0];

                 term = politicalWords.exec(title);
               }


               div = document.createElement('div'),
               div.innerHTML = '<p>Misplaced political crap: ' + terms.join(", ") + ' </p> ';
               row.parentNode.insertBefore(div, row.nextSibling.nextSibling.nextSibling);
            }
            // Hides offending article.
            //
            //row.parentNode.parentNode.style.display = 'none';
        }
    }
    else if (term = alwaysDownmoded.exec(title)) {
               setTimeout("mod('"+storyID+"',0);",5000);
               row.parentNode.style.background='#D6FFCF';//#FFF8C6';
               downmods+=1;
               var terms = new Array();
                   count = 0;

               while (term != null)
               {
                 duplicate = false;
                 for (item in terms)
                 {
                   if (terms[item].toUpperCase() == term[0].toUpperCase())
                      duplicate = true;
                   //else
                   //   alert(item + ' ' + term);
                 }

                 if (!duplicate) terms[count++] = term[0];

                 term = alwaysDownmoded.exec(title);
               }


               div = document.createElement('div'),
               div.innerHTML = '<p>General topics that suck: ' + terms.join(", ") + ' </p> ';
               row.parentNode.insertBefore(div, row.nextSibling.nextSibling.nextSibling);
    }

    if (hiddenWords.exec(title)) { row.parentNode.parentNode.style.display = 'none'; }
}

// Inserts results under the alien.
    var tbl = document.getElementById('header-bottom-right'),
        div = document.createElement('div'),
        msg1 = 'Downvoted ' + downmods + ' stories';
        msg2 = 'Upvoted ' + upmods + ' stories';
    //GM_log(msg);
    if (!tbl) return;
    div.innerHTML = '<p><i>' + msg1 + ' </i> <br> ';
    div.innerHTML += '<i>' + msg2 + '<br> (Reddit Content Filter).</i></p>';
    tbl.parentNode.insertBefore(div, tbl.nextSibling);