Version 2.0
- "intelligent" AnimePahe search logic - independent design - search Animes without year in name
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
// ==UserScript==
|
||||
// @name aniSearch Enhancer
|
||||
// @namespace http://git.nivram.io/marvinlehmann/ani-search-enhancer
|
||||
// @version 1.90
|
||||
// @version 2.0
|
||||
// @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
|
||||
@@ -20,8 +20,16 @@
|
||||
content:"\\f002";
|
||||
}
|
||||
|
||||
#page-action-stream {
|
||||
background-color: #ee8600 !important;
|
||||
}
|
||||
|
||||
#page-action-stream:hover {
|
||||
background-color: #58626b !important;
|
||||
background-color: #ee8600 !important;
|
||||
}
|
||||
|
||||
#page-action-stream span {
|
||||
line-height: 26px !important;
|
||||
}
|
||||
|
||||
#stream-links {
|
||||
@@ -29,23 +37,70 @@
|
||||
-webkit-appearance: none;
|
||||
appearance: none;
|
||||
border: none;
|
||||
|
||||
|
||||
background-color: #58626b;
|
||||
background-color: #ee8600;
|
||||
color: #e6e6e6;
|
||||
box-shadow: none;
|
||||
padding: 0 5px;
|
||||
}
|
||||
|
||||
#stream-links > option {
|
||||
direction: ltr;
|
||||
font-weight: bold;
|
||||
}
|
||||
</style>`);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
function getElementByXpath(path) {
|
||||
return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
|
||||
}
|
||||
|
||||
const animeTitle = document.getElementById("htitle").textContent;
|
||||
const animeReleaseYear = document.querySelector("header .release_year").textContent.match(/\d+/);
|
||||
/** @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 = getElementByXpath('//*[@id="infodetails"]//span[text()="Typ"]/../text()').textContent;
|
||||
|
||||
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*/ `<ul id="page-action" class="inline"></ul>`);
|
||||
}
|
||||
@@ -79,28 +134,64 @@
|
||||
return option;
|
||||
}
|
||||
|
||||
stream_links.insertAdjacentElement("beforeend", stylized(new Option("Piracy Index", "https://piracy.moe/"), { direction: "rtl", fontWeight: "bold" }));
|
||||
stream_links.insertAdjacentElement("beforeend", new Option("AniCloud", "https://anicloud.io/search?q=" + encodedTitle));
|
||||
stream_links.insertAdjacentElement("beforeend", new Option("AnimeUltima", "https://www16.animeultima.eu/search?search=" + encodedTitle));
|
||||
stream_links.insertAdjacentElement("beforeend", stylized(new Option("Twist.moe", "http://twist.moe"), { fontStyle: "italic", color: "lightgray" }));
|
||||
stream_links.insertAdjacentElement("beforeend", stylized(new Option("Piracy Index", "https://piracy.moe/"), {
|
||||
direction: "rtl",
|
||||
fontWeight: "bold"
|
||||
}));
|
||||
stream_links.insertAdjacentElement("beforeend", new Option("AniCloud", "https://anicloud.io/search?q=" + encodedTitleWithoutYear));
|
||||
stream_links.insertAdjacentElement("beforeend", new Option("AnimeUltima", "https://www16.animeultima.eu/search?search=" + encodedTitleWithoutYear));
|
||||
stream_links.insertAdjacentElement("beforeend", stylized(new Option("Twist.moe", "http://twist.moe"), {
|
||||
fontStyle: "italic",
|
||||
color: "#DDD"
|
||||
}));
|
||||
|
||||
GM_xmlhttpRequest({
|
||||
method: "GET",
|
||||
url: "https://animepahe.com/api?m=search&l=3&q=" + encodedTitle,
|
||||
url: "https://animepahe.com/api?m=search&l=8&q=" + encodedTitleWithoutYear,
|
||||
responseType: "json",
|
||||
onload: function (resp) {
|
||||
if (resp.response.total > 0) {
|
||||
const firstResult = resp.response.data[0];
|
||||
const targetPage = "https://animepahe.com/anime/" + firstResult.session;
|
||||
stream_links.insertAdjacentElement("beforeend", new Option("AnimePahe", targetPage));
|
||||
const typeMapping = {
|
||||
"TV-Serie": "TV",
|
||||
"OVA": "OVA",
|
||||
"Film": "Movie",
|
||||
"Bonus": "Special"
|
||||
};
|
||||
|
||||
// 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);
|
||||
// }
|
||||
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: "gray" }));
|
||||
stream_links.insertAdjacentElement("beforeend", stylized(new Option("AnimePahe", "https://animepahe.com"), {
|
||||
fontStyle: "italic",
|
||||
color: "#DDD"
|
||||
}));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user