Sort Youtube Comments by Rating

By EdLolington Last update Sep 14, 2011 — Installed 1,490 times.

Jan 16, 2012 Fix

in
Subscribe to Jan 16, 2012 Fix 7 posts, 4 voices



Thane Ross User
FirefoxWindows

// ==UserScript==
// @name           Sort Youtube Comments 
// @namespace      ytubecommentsort
// @include        http://www.youtube.com/*
// ==/UserScript==

if (location.href.toString().indexOf("all_comments?") != -1) 
	init();
	
	
function init() {
	//remove all nodes from the comment area, storing them in an array
	//sort based on their ratings
	//return sorted array
	//add nodes back into place
	
	var sortLink = document.createElement("a");
	var options = document.getElementById("threaded-option");
	sortLink.setAttribute("href", "#");
	sortLink.appendChild(document.createTextNode("Sort by rating"));
	sortLink.addEventListener("mousedown", function() {
		options.innerHTML = options.innerHTML.replace("Sort by time", "< comments.length; i++) {
		com.push(comments[i]);
	}
	com.sort(sortByScore);
	for (var i = 0; i < com.length; i++) {
		commentArea.appendChild(com[i]);
	}
}

function sortByScore(a, b) {
	var aVal = 0;
	var bVal = 0;
	if (a.getAttribute) {
		aVal = parseInt(a.getAttribute("data-score"));
	}
	if (b.getAttribute) {
		bVal = parseInt(b.getAttribute("data-score"));
	}
	return bVal - aVal;
}

 
SUPER_KEG Scriptwright
FirefoxWindows

Doesnt work for me! the "Sort by rating" option disapears! Please help :(

 
Thane Ross User
FirefoxWindows

Doh. Looks like my last post didn't paste in properly. Try this instead.

http://pastebin.com/peHKDfFw

 
drhouse Scriptwright
FirefoxWindows

Woah, I was surprised, it really works in Firefox.. even after Youtube's site redesign. First you need to click on 'All Comments' and the 'Sort by rating' link still shows up. I wonder if this could be used for something.

 
sslojpdz Scriptwright
FirefoxWindows

Hey, now the script is broken again, could you fix it mr Ross`? :)

 
drhouse Scriptwright
ChromeWindows

I fixed it:
http://pastebin.com/FpTZvEdT

 
drhouse Scriptwright
FirefoxWindows

I wrote a script using the fixed version, loads it in a frame:

YouTube Top Rated Sorted Comments
http://userscripts.org/scripts/show/154869