Files
ani-search-enhancer/ani-search-enhancer.user.js
Marvin Lehmann 15ee13ef9f Added support for Masterani.me
and changed 'id' to 'class'...
2018-07-24 14:35:24 +02:00

50 lines
3.0 KiB
JavaScript

// ==UserScript==
// @name aniSearch Enhancer
// @namespace http://github.com/marvinlehmann/ani-search-enhancer
// @version 1.6
// @description Adds buttons to the info site of an anime on aniSearch which links you directly to various streaming portals.
// @author Marvin Lehmann
// @grant GM_xmlhttpRequest
// @include /^https?://www.anisearch.de/anime/.*$/
// @connect masterani.me
// @require http://code.jquery.com/jquery-latest.js
// @downloadURL http://raw.githubusercontent.com/marvinlehmann/ani-search-enhancer/master/ani-search-enhancer.user.js
// @supportURL http://github.com/marvinlehmann/ani-search-enhancer/issues
// ==/UserScript==
this.$ = this.jQuery = jQuery.noConflict(true);
$(function() {
$('head').append('<style>.page-action-search:before{content:"\\f002";}</style>');
const animeTitle = $('#htitle > span[itemprop=name]').text();
const animeReleaseYear = $('#htitle > span.release_year').text().replace(/\(|\)/g, '');
if (animeTitle) {
const encodedTitle = encodeURI(animeTitle).replace(/'/g, "%27");
if ($('#page-action').length === 0) $('#htitle').after('<ul id="page-action" class="inline"></ul>');
$('#page-action').append('<li class="page-action-search" onclick="window.open(\'http://kissanime.ru/Search/Anime?keyword=' + encodedTitle + '\', \'_blank\');"><span>KissAnime</span></li>');
$('#page-action').append('<li class="page-action-search" onclick="window.open(\'https://proxer.me/search?s=search&name=' + encodedTitle + '&typ=all-anime#top\', \'_blank\');"><span>Proxer</span></li>');
$('#page-action').append('<li class="page-action-search" onclick="window.open(\'https://9anime.to/search?keyword=' + encodedTitle + '\', \'_blank\');"><span>9Anime</span></li>');
// Search for the anime on masterani.me - possibly returns url to wrong anime
GM_xmlhttpRequest({
method: 'GET',
// Masterani's search is limited to 30 chars
// sb=true only returns the "best" results (?)
url: 'https://www.masterani.me/api/anime/search?search=' + encodedTitle.substring(0, 30) + '&sb=true',
responseType: 'json',
onload: function(data) {
if (data.response.length > 0) {
const firstResult = data.response[0];
const masteraniPage = 'https://www.masterani.me/anime/info/' + firstResult.slug;
const $masteraniButton = $('<li class="page-action-search" onclick="window.open(\'' + masteraniPage + '\', \'_blank\');"><span>Masterani</span></li>').appendTo($('#page-action'));
// Did we possibly get the wrong one?
if (!firstResult.started_airing_date.includes(animeReleaseYear)) {
$masteraniButton.prop('title', 'Target page may be incorrect.');
$masteraniButton.css('opacity', 0.5);
}
}
}
});
}
});