[MAL] Additional features

Adds image and torrent search for each anime / manga entry, removes search results already on the user's list and removes a few adds.

Versione datata 13/05/2017. Vedi la nuova versione l'ultima versione.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

You will need to install an extension such as Tampermonkey to install this script.

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

// ==UserScript==
// @name         [MAL] Additional features
// @description  Adds image and torrent search for each anime / manga entry, removes search results already on the user's list and removes a few adds.
// @version      1.0.1
// @author       MetalTxus

// @include      https://myanimelist.net/topanime.php?*
// @include      https://myanimelist.net/topmanga.php?*
// @include      https://myanimelist.net/anime*
// @include      https://myanimelist.net/manga*

// @icon         https://dl.dropbox.com/s/8m20m7iqc5bz1ke/mal.png
// @namespace    https://greasyfork.org/users/8682
// ==/UserScript==

(function() {
    'use strict';

	var MEDIA_TYPE = {
        anime: { id: '1_2', label: 'anime' },
        manga: { id: '3_1', label: 'manga'}
    }, CSS =
        '<style>' +
            '.custom-search-wrapper a { text-decoration: none; font-size: 16px; transition: .3s;}' +
            '.custom-search-wrapper a:hover { color: rgba(80,116,200,.9); }' +
            '.fa-magnet::before { content: "\\f076" }' +
            '.fa-picture-o::before { content: "\\f03e" }' +
        '</style>';

	function removeResultsInOwnList () {
		$('.ranking-list .btn-anime-watch-status:not(.notinmylist)').parents('.ranking-list').remove();
		$('.js-block-list [title="Completed"],' +
		  '.js-block-list [title="Dropped"],' +
		  '.js-block-list [title="Plan to Watch"]'
		 ).parents('.js-seasonal-anime, tr').remove();
	}

	function addLinkToSearch () {
		$('#contentWrapper h1 span[itemprop="name"]').each(function (i, element) {
			element = $(element);

			var mediaType = location.href.indexOf('https://myanimelist.net/anime') > -1 ? MEDIA_TYPE.anime : MEDIA_TYPE.manga,
				title = element.text();

            var searchWrapper = $('<span class="custom-search-wrapper"></span>');

            var picturesAnchor = $('<a href="https://www.google.es/search?tbm=isch&q=' + encodeURI(title) + ' ' + mediaType.label + '"></a>');
            var picturesIcon = $('<i class="fa fa-picture-o" title="Search for pictures"></i>');
            picturesAnchor.append(picturesIcon);
			searchWrapper.append(' ', picturesAnchor);

            var torrentAnchor = $('<a href="https://nyaa.si/?f=0&s=seeders&o=desc&c=' + mediaType.id + '&q=' + encodeURI(title) + '"></a>');
            var torrentIcon = $('<i class="fa fa-magnet" title="Search for torrents"></i>');
            torrentAnchor.append(torrentIcon);
			searchWrapper.append(' ', torrentAnchor);

			element.append(searchWrapper);
		});
	}

    function removeAdds () {
        $('[href^="/membership?"]').each(element => $(element).parents('div').eq(0).remove());
        $('._unit').each(element => $(element).remove());
    }

    $(CSS).appendTo('head');
    setTimeout(removeAdds, 1000);
	removeResultsInOwnList();
	addLinkToSearch();
})();