Google Chrome Extension: Reddit All Comments Viewer (Expand all comments in Reddit)

Published: by

  • Categories:

Ever noticed those "load more comments" button, this extension expands all those links.

Please note that use this feature judiciously as it increases the load on reddit servers and that was the primary reason not all comments are displayed by default.

The idea behind developing:- It was a top-post with more than 2000 comments. I had read a comment earlier but later when I reopend the link to search for that comment with the keyword (Yes, I remembered the keywork to search for the comment), it wasn't on the page. The sole reason for this was it being not shown due to "load more comments".

Link to the Extension at Web Store: https://chrome.google.com/webstore/detail/djifpbcmaphjihhelcdeannijfelfnbh

Github: https://github.com/shadyabhi/reddit-all-comments-viewer

Content Script used:

function runAgain(){
	//Run every one second
	window.setTimeout(addButton,1e3)
	}

function addButton(){
	//All buttons have class as "button"
	var first_button = document.getElementsByClassName("button")[0];
	if (first_button == null){
		alert("Sorry, no comments to expand");
		return;
	}

	if (first_button.innerHTML == "loading..."){
		first_button.className = ""; //To fix later
	}
	else{
	   var theEvent = document.createEvent("MouseEvent");
	   theEvent.initMouseEvent("click", true, true, window, 0, 0, 0, 0, 0, false, false, false, false, 0, null);
	   first_button.dispatchEvent(theEvent);
	}

	if(first_button.id) 
		runAgain();
	};

//Link created and added as child to "pane"
var pane = document.getElementsByClassName("panestack-title")[0];
var newlink = document.createElement("a");
newlink.appendChild(document.createTextNode("Load all comments"));
newlink.id = "loadmorecomments";
newlink.href = "javascript:void(0)";
newlink.className="title-button ";
newlink.title = 'Opens all "load more comments" link every 1 second';
newlink.addEventListener('click', runAgain, false);
pane.appendChild(newlink);