Tyrel_MAL_Sort_by_Score

Adds MAL scores to animelist and sorts them if you click on the header.

< Feedback on Tyrel_MAL_Sort_by_Score

Review: OK - script works, but has bugs

§
Posted: 12-01-2020

I made a fix for this script

// ==UserScript== // @name TyrelMALSortbyScore // @namespace https://greasyfork.org/de/scripts/30598-tyrel-mal-sort-by-score // @version 0.2 // @description Adds MAL scores to animelist and sorts them if you click on the header. // @author Ghost // @match https://myanimelist.net/animelist/* // @grant none // ==/UserScript==

// Initialize the table header "Rank Score" $(".header-title.score").after('Rank Score'); // Initialize the cells for "Rank Score" $(".data.score").each(function(index) { $(this).after(''); });

$(document).ready(function() { //When document has loaded

setTimeout(function() {

$(".list-item .more-info").each(function(index, item) {
    if(index){
        var animeID = $(this);
        animeID = animeID[0];
        animeID = animeID.attributes;
        animeID = animeID.id.nodeValue.replace("more-", "");
        var tableRows = $(".list-item .data.rank");
        var currentScoreCell = tableRows.eq(index);

        $.ajax({
            method: "GET",
            url: "https://myanimelist.net/anime/"+animeID,
            dataType: "HTML",
            success: function(text) {
                var rankScore = text.match(/ratingValue\">\d+\.\d+/g)[0].replace('ratingValue">', "");

                currentScoreCell.html(rankScore);
            }
        });
    }
});

// Sorter
$('th.header-title.ranking').click(function(){
    var table = $('.list-table');
    var rows = table.find('tbody tr.list-table-data').toArray().sort(comparer($(this).index()));
    this.asc = !this.asc;

    if (!this.asc){rows = rows.reverse();}
    for (var i = 0; i < rows.length; i++){
        table.append(rows[i]);
    }
});

function comparer(index) {
    return function(a, b) {
        var valA = getCellValue(a, index), valB = getCellValue(b, index);
        return $.isNumeric(valA) && $.isNumeric(valB) ? valA - valB : valA.localeCompare(valB);
    };
}

function getCellValue(row, index){
    return $(row).children('td').eq(index).html();
}

}, 1000); //ZA WARUDO! One Second Has Passed.

});

Post reply

Sign in to post a reply.