MyAnimeList(MAL) - Com-to-Com Links

Add Com-to-Com link between user and comment user for every comment.

À partir de 2015-10-17. Voir la dernière version.

// ==UserScript==
// @name            MyAnimeList(MAL) - Com-to-Com Links
// @version         1.0.0
// @description	    Add Com-to-Com link between user and comment user for every comment.
// @author          Cpt_mathix & N_Ox
// @include         http://myanimelist.net/profile*
// @include         http://myanimelist.net/comments*
// @grant           none
// @namespace https://greasyfork.org/users/16080
// ==/UserScript==

if (document.location.href.indexOf('profile') > -1)
	comtocom(document.getElementById('lastcomment').getElementsByTagName('a')[1].href);
else
	comtocom(document.location.href);

function comtocom(url) {
    if (typeof jQuery == 'undefined') $ = unsafeWindow.$;

    var i = url.indexOf('id=');
    if (i == -1) return;
    url = 'http://myanimelist.net/comtocom.php?id1=' + url.substr(i + 3) + '&id2=';

    if (document.location.href.indexOf('profile') == -1) {
        $('div[id^=comBox] > table > tbody > tr').each(function () {
            var avatar = $('.picSurround img', this);
            if (!avatar.length) return;

            var com = $('div[id^=com]:not([id^=comtext])', this);
            if (!com.length) return;
            if (com.children().length == 3) return;

            var id = avatar.attr('src');
            var i = id.indexOf('thumbs/');
            if (i == -1) return;
            id = id.substr(i + 7, id.indexOf('_') - i - 7);

            com.append(
                $('<div style="margin-top:10px"/>').append(
                    $('<small/>').append(
                        $('<a title="Comment-to-Comment">Com-to-Com</a>').attr('href', url + id))));
        });
    } else {
        $('div[id^=comBox]').each(function () {
            var avatar = $('img', this);
            if (!avatar.length) return;
            
            var com = $('div[id^=comtext]', this);
            
            var id = avatar.attr('src');
            var i = id.indexOf('userimages/');
            if (i == -1) return;          
            id = id.substr(i + 11, id.indexOf('.jpg') - i - 11);

            com.append(
                $('<div style="margin-top:10px"/>').append(
                    $('<small/>').append(
                        $('<a title="Comment-to-Comment">Com-to-Com</a>').attr('href', url + id))));
        });
    }
}