// ==UserScript== // @name aniSearch Enhancer // @namespace http://git.nivram.io/marvinlehmann/ani-search-enhancer // @version 2.1 // @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 animepahe.com // @connect twist.moe // @downloadURL http://git.nivram.io/marvinlehmann/ani-search-enhancer/raw/master/ani-search-enhancer.user.js // @supportURL http://git.nivram.io/marvinlehmann/ani-search-enhancer/issues // ==/UserScript== (function () { 'use strict'; document.head.insertAdjacentHTML("beforeend", //html ``); class AnimePaheSearchResult { constructor() { /** @type {number} */ this.episodes = 0; /** @type {number} */ this.id = 0; /** @type {string} */ this.poster = ""; /** @type {string} */ this.relevance = ""; /** @type {number} */ this.score = 0; /** @type {string} */ this.season = ""; /** @type {string} */ this.slug = ""; /** @type {string} */ this.session = ""; /** @type {string} */ this.status = ""; /** @type {string} */ this.title = ""; /** @type {string} */ this.type = ""; /** @type {number} */ this.year = 0; } } const animeTitle = document.getElementById("htitle").textContent; /** @type {number} */ let animeReleaseYear = null; let anime_release_year = document.querySelector("header .release_year"); if (anime_release_year) { animeReleaseYear = parseInt(anime_release_year.textContent.match(/\d{4}/)); } else { let tmp = document.getElementById("htitle").textContent.match(/\((\d{4})\)/); if (tmp) { animeReleaseYear = parseInt(tmp[1]); } } let animeStatus = document.querySelector('#information [lang=ja] ~ .status').textContent.split(": ")[1]; let animeType = document.querySelector("#information .type").childNodes[1].textContent.trim().split(',')[0] if (animeTitle) { const encodedTitle = encodeURI(animeTitle).replace(/'/g, "%27"); const encodedTitleWithoutYear = encodeURI(animeTitle.replace(/ \(\d{4}\)/g, "")).replace(/'/g, "%27"); if (!document.getElementById("page-action")) { document.getElementById("htitle").insertAdjacentHTML("beforeend", /*html*/ ``); } document.getElementById("page-action").insertAdjacentHTML("beforeend", //html `
  • `); const stream_links = document.getElementById("stream-links"); const page_action_stream = document.getElementById("page-action-stream"); const clickHandler = function (e) { if (e.target === e.currentTarget) { const targetUrl = stream_links.value; if (targetUrl) { window.open(targetUrl, "_blank"); } } }; page_action_stream.onclick = clickHandler; /** @param {HTMLOptionElement} option */ const stylized = (option, styles) => { Object.assign(option.style, styles); return option; } stream_links.insertAdjacentElement("beforeend", stylized(new Option("Piracy Index", "https://theindex.moe/"), { direction: "rtl", fontWeight: "bold" })); stream_links.insertAdjacentElement("beforeend", new Option("AniCloud", "https://anicloud.io/search?q=" + encodedTitleWithoutYear)); GM_xmlhttpRequest({ method: "GET", url: "https://animepahe.com/api?m=search&l=8&q=" + encodedTitleWithoutYear, responseType: "json", onload: function (resp) { const typeMapping = { "TV-Serie": "TV", "OVA": "OVA", "Film": "Movie", "Bonus": "Special" }; const statusMapping = { "Abgeschlossen": "Finished Airing", "Laufend": "Currently Airing", "Zukünftig": "" } if (resp.response.total > 0) { /** @type {AnimePaheSearchResult[]} */ const data = resp.response.data; /** @type {AnimePaheSearchResult} */ let chosenResult = data[0]; /** @type {number[]} */ let potential = Array(data.length); for (let [index, value] of data.entries()) { potential[index] = 0; if (value.year === animeReleaseYear || (value.season === "Winter" && value.year - 1 === animeReleaseYear)) { potential[index]++; } if (value.type === typeMapping[animeType]) { potential[index] += 2; } if (value.status === statusMapping[animeStatus]) { potential[index]++; } } chosenResult = data[potential.indexOf(Math.max(...potential))]; const targetPage = "https://animepahe.com/anime/" + chosenResult.session; stream_links.insertAdjacentElement("beforeend", new Option("AnimePahe", targetPage)); } else { stream_links.insertAdjacentElement("beforeend", stylized(new Option("AnimePahe", "https://animepahe.com"), { fontStyle: "italic", color: "#DDD" })); } } }); } })();