// This script hides all comments and replies to them by darryl or whoever you choose on TechDirt.com.

// This work is licensed under the Creative Commons Share-Alike License. To view a copy of this license, visit http://creativecommons.org/licenses/by-sa/3.0/; or, (b) send a letter to Creative Commons, 171 2nd Street, Suite 300, San Francisco, California, 94105, USA.

// Please note that while I do not care about attribution and do not require attribution for any use, there does not appear to be

// any CC license that doesn't require attribution.  Consider this a CC:Share-Alike license without an attribution requirement.

// ==UserScript==

// @name               Hide annoying Techdirt commenters

// @namespace          tag:nasch@techdirt

// @description        Collapses all discussions on TechDirt from a list of commenter names

// @include            http://www.techdirt.com/articles/*

// ==/UserScript==

// In case someone wants to see the darryl comment (don't ask me why)

this.showConversation = function () {

    var commentId = this.id.substr("showMsg".length, this.id.length);

    var cmt = document.getElementById(commentId);

    // Hide the clickable message

    this.style.display = "none";

    // Show the original message

    cmt.style.display = "block";

   

    // Show any replies

    var replies = findReplies(this.parentNode);

    if(replies != null){

            replies.style.display = "block";

    }

}

this.findComments = function (commenterNames) {                    

   

    var elementList = document.getElementsByClassName("commentname");

    var rtn = new Array();

   

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

            var commenter = elementList[i];

            for (var x = 0; x < commenterNames.length; x++){

                    if (commenter.innerHTML.indexOf(commenterNames[x]) > -1) {

                            var parent = commenter.parentNode; // This will be the div holding the comment.  It's enclosed by an li

                            console.log("Found a comment by " + commenterNames[x]);

                            rtn[rtn.length] = parent;

                            break;

                    }

            }

    }

   

    return rtn;

}

this.findReplies = function(listItemElement) {

   

    var  next = listItemElement.nextSibling.nextSibling;

    if(next != null && next.tagName.toLowerCase() == "ul"){

            return next;

    }

   

    return null;

}

// Execution starts here

var comments = findComments(new Array("darryl", "Darryl", "John Paul Jones", "Buck Lateral", “average_joe”)); // Add or change commenters here like so: new Array("darryl", "John Doe")

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

           

            var comment = comments[i];

           

            comment.style.display = "none"; // The most important line in the script!!

           

            // Insert a message the user can click on to show the hidden message tree

            var el = document.createElement('span');

            el.innerHTML = 'Click to show hidden conversation';

            el.style.color = "purple";  // Make it whatever color you like!

            el.id = "showMsg" + comment.id;

            el.addEventListener("click", showConversation, true);

            var parent = comment.parentNode;

            parent.appendChild(el);

           

            // Hide replies

            var replies = findReplies(parent);

            if(replies != null){

                    replies.style.display = "none";

            }

}