Greasy Fork is available in English.

Myshows.me comments sorter

Add sort button to comments on myshows.me

// ==UserScript==
// @name         Myshows.me comments sorter
// @namespace    https://greasyfork.org/ru/scripts/46629-sort-comments
// @version      2.5.0
// @description  Add sort button to comments on myshows.me
// @author       Sarge
// @match        https://myshows.me/view/episode/*
// @match        https://myshows.me/movie/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant        none
// @run-at       document-idle
// ==/UserScript==

var $comments = $("div.Comments-tree > div");

//including trees
/*$(".сomment > .comment-list").each(function() {
    var $this = $( this );
    $this.next().appendTo($this);
});*/

//sort comments
var sortComments = function (){

   $("html").animate({
        scrollTop: $(".Footer").offset().top
      });
    setTimeout(() => {

    var comment_list = $(".Comments-tree > .CommentList > .Comment");

    var sorted_list = comment_list.sort(function(a,b) {
        var rating_node = "> .Comment__body > .Comment__actions > .CommentFooter > .CommentFooter__voting > .CommentRatingVoters > div > .CommentRating > .CommentRating__value";
        var one = $(a).find(rating_node).text().replace(/(\r\n|\n|\r|\s)/gm, "") ||0;
        var two = $(b).find(rating_node).text().replace(/(\r\n|\n|\r|\s)/gm, "") ||0;
        return two - one;
    });

    $comments.slideUp("slow", function(){ sorted_list.appendTo($comments); });
    $comments.slideDown("slow", function(){ $('#sortingButton').css({"background-color": "green"}).text('Отсортированно'); });
    },1000);
    $("html").animate({
        scrollTop: $("#sortingButton").offset().top
      });
};
/*window.onload = function(){
        //add sort button
        $comments.prepend('<button id="sortingButton" class="sortButton comment-form__controls RoundedButton primary m" onclick="sortComments()">Сортировать</button>');
        window.sortComments = sortComments;
};*/
window.addEventListener("load", () => setTimeout(function(){
        //add sort button
        $comments.prepend('<button id="sortingButton" class="sortButton comment-form__controls RoundedButton primary m" onclick="sortComments()">Сортировать</button>');
        window.sortComments = sortComments;
},1000));