Quantcast
Channel: Blogs - MyAnimeList.net
Viewing all articles
Browse latest Browse all 48425

GreaseMonkey JS patches for MAL

$
0
0
// ==UserScript==
// @name MAL JS patches
// @namespace ErgoSis
// @include http://myanimelist.net/*
// @description Random fixes for MAL 
// @grant none
// @run-at document-start
// ==/UserScript==

//Add button for increasing chapter number from manga's page or ep from anime's
//Show statistics delta since the last visit on the user panel
//Remember last search type
//Jump to first exact match of searched type if found in global search

document.addEventListener('DOMContentLoaded', function() {
//Remember last search type
var search_for = localStorage["searchfor"] || '0',
    search_type = $('#topSearchValue :eq('+search_for+')').val();

    setTimeout(function() { $('#topSearchValue').prop('selectedIndex', parseInt(search_for, 10) || 0);}, 0);
    $('#topSearchValue').on('change', function() {
        search_for = $(this).prop('selectedIndex');
        search_type = $(this).find(":selected").val();
    });
//Jump to first exact match if found in global search
    if (~location.pathname.indexOf('/search')) {
        var type = search_type.toLowerCase().replace('person','people').replace('character','characters');
        var first = $('#'+type+'+article:eq(0)>:first-child>div:eq(1)>a[id]');
        if ($('.js-advancedSearchText').val().replace(/\s+/g,' ').trim() === first.text().replace(/\s+/g,' ').trim()) {
            location.href = first.prop('href');
        }
//Add button for increasing chapter number from manga's page or ep from anime's
    } else if(~location.pathname.indexOf('/manga')){
        $('&nbsp<input type="button" id="chapters_plusone" onclick="document.getElementById(\'myinfo_chapters\').value++" class="inputtext" value="+" />').insertBefore('#myinfo_chapters');
        $('&nbsp<input type="button" id="volumes_plusone" onclick="document.getElementById(\'myinfo_volumes\').value++" class="inputtext" value="+" />').insertBefore('#myinfo_volumes');
        $('#myinfo_chapters,#myinfo_volumes').css({'text-align':'center'});
    } else if (~location.pathname.indexOf('/anime')) {
        $('&nbsp<input type="button" id="episodes_plusone" onclick="var we=$(\'#myinfo_watchedeps\')[0], eps=parseInt($(\'#curEps\').text()); if (isNaN(eps) || parseInt(we.value || \'0\') < eps) we.value++" class="inputtext" value="+" />').insertBefore('#myinfo_watchedeps');
        $('#myinfo_watchedeps').css({'text-align':'center'});
//Show statistics delta since the last visit on the user panel
    } else if (location.pathname === '/'){
        var aviews = parseInt($('.my_statistics tr:eq(2) td:eq(1)').text().trim().replace(/,/g,'').match(/\d+/)[0], 10),
            aviews_stor = parseInt(localStorage["aviews"] || "0", 10),
            mviews = parseInt($('.my_statistics tr:eq(3) td:eq(1)').text().trim().replace(/,/g,'').match(/\d+/)[0], 10),
            mviews_stor = parseInt(localStorage["mviews"] || "0", 10),
            pviews = parseInt($('.my_statistics tr:eq(4) td:eq(1)').text().trim().replace(/,/g,'').match(/\d+/)[0], 10),
            pviews_stor = parseInt(localStorage["pviews"] || "0", 10);
        if (!isNaN(aviews) && !isNaN(mviews) && !isNaN(pviews)){
            if (aviews_stor < aviews){
                localStorage["aviews"] = aviews;
                $('<span style="color:red;font-size:7px;vertical-align:top;"> +'+(aviews-aviews_stor)+'</span> ').appendTo($('.my_statistics tr:eq(2) td:eq(1)'));
            }
            if (mviews_stor < mviews){
                localStorage["mviews"] = mviews;
                $('<span style="color:red;font-size:7px;vertical-align:top;"> +'+(mviews-mviews_stor)+'</span> ').appendTo($('.my_statistics tr:eq(3) td:eq(1)'));
            } 
            if (pviews_stor < pviews){
                localStorage["pviews"] = pviews;
                $('<span style="color:red;font-size:7px;vertical-align:top;margin-right:4px;"> +'+(pviews-pviews_stor)+'</span> ').insertBefore($('.my_statistics tr:eq(4) td:eq(1)>small'));
            }
        }
    }
}, false);

Viewing all articles
Browse latest Browse all 48425

Trending Articles