Jan 16, 2012 Fix
![]() ![]() |
// ==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;
}
|
![]() ![]() |
Doesnt work for me! the "Sort by rating" option disapears! Please help :( |
![]() ![]() |
Doh. Looks like my last post didn't paste in properly. Try this instead. |
![]() ![]() |
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. |
![]() ![]() |
Hey, now the script is broken again, could you fix it mr Ross`? :) |
![]() ![]() |
I fixed it:
|
![]() ![]() |
I wrote a script using the fixed version, loads it in a frame: YouTube Top Rated Sorted Comments
|


