AniList MultiTitle Display

Adds the non-primary titles to the title display.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         AniList MultiTitle Display
// @namespace    http://tampermonkey.net/
// @version      0.2
// @description  Adds the non-primary titles to the title display.
// @author       Bane
// @match        https://anilist.co/anime/*
// @match        https://anilist.co/manga/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js
// @require      http://code.jquery.com/jquery-3.4.1.min.js
// @require https://greasyfork.org/scripts/6250-waitforkeyelements/code/waitForKeyElements.js?version=23756
// @grant        none
// ==/UserScript==

/* globals jQuery, $, waitForKeyElements */

function GetTitles(jnode)
{
    console.log("Getting AniTitles!");

    //The already existing title
    var aniTitle = document.querySelector("#app > div.page-content > div > div.header-wrap > div.header > div.container > div.content > h1")
    aniTitle.innerHTML = aniTitle.innerText; //Replace the HTML with the innerText cuz it's neater

    var oldTitle = aniTitle.innerText; //Store the user preference
    var oldTitle2 = aniTitle.innerHTML; //Double store because weirdness in some titles, discovered thanks to https://anilist.co/anime/97634/
    aniTitle.innerHTML += "</br></br>" //Add line breaks to separate the preference from the others

    //var sets = jnode;
    var sets = document.getElementsByClassName("data-set"); //Searched all the data values on the sidebar

    var title = ""; //Creates empty title string for later

    //The types we are looking to add
    var types = ["Romaji", "English", "Native", "Synonyms"];

    SetTitles();

    function SetTitles()
    {
        for(var i = 0; i < sets.length; i++)
        {
            //Get the type we are looking at in the loop
            var typeCheck = sets[i].getElementsByClassName("type")[0].innerText;

            //If the type is in our wanted types...
            if(types.indexOf(typeCheck) > -1)
            {
                //...continue and add it to the title.
                console.log("Right Ani type found");
                AddTitle(i);
            }
        }
    }

    function AddTitle(i)
    {
        title = sets[i].getElementsByClassName("value")[0].innerHTML; //Get the text from the value.
        title = title.replace(/ +/g, " "); //Removes double spaces (for some reason there's a few, such as at https://anilist.co/anime/98448/)

        if(!(title == oldTitle || title == oldTitle2)) //If the title is NOT the same as the user preference one...
        {
            //...add it.
            aniTitle.innerHTML += title + "</br>";
        }
    }
}

waitForKeyElements("div.sidebar", GetTitles);