Greasy Fork

Find The Correct Watch Order And All Related Entries+Live-Actions+Doramas + Copy Entry Title

The script shows you the Correct Watch Order And All Related Entries. The script can also auto find if an anime has any Live-Action or Drama adaptations, and the script can Copy The Anime/Manga Title.

目前为 2021-01-14 提交的版本。查看 最新版本

// ==UserScript==
// @name         Find The Correct Watch Order And All Related Entries+Live-Actions+Doramas + Copy Entry Title
// @namespace    Search for Live-Actions\Doramas\All Related Entries + Correct Watch Order + Copy Entry Title
// @version      2.0.0.11
// @description  The script shows you the Correct Watch Order And All Related Entries. The script can also auto find if an anime has any Live-Action or Drama adaptations, and the script can Copy The Anime/Manga Title.
// @author       hacker09
// @include      /^https:\/\/myanimelist\.net\/anime\/[\d]+(\/.*)?/
// @include      /^https:\/\/myanimelist\.net\/manga\/[\d]+(\/.*)?/
// @icon         https://www.google.com/s2/favicons?domain=myanimelist.net
// @grant        none
// @run-at       document-end
// ==/UserScript==
//The lines below are the beginning of the function
(function() {
  var AllChiakiAnimeTitles = []; //Creates a new blank array
  var titleElem = document.querySelector(".title-name").firstChild; //Find and Select the entry title element
  var findButton = document.createElement("a"); //Creates an "a" element to show a button later
  var copyButton = document.createElement("a"); //Creates an "a" element so the button will appear
  var chiakiButton = document.createElement("a"); //Creates an "a" element so the button will appear
  var animeid = location.pathname.match(/\d+/)[0]; //Get the anime id to add on the chiaki website url
  var ChiakiAnimeTitle, ChiakiAnimeTitleWithSymbols, ShortestChiakiAnimeTitleWithSymbols, ShortestChiakiAnimeTitle, response2, html2, newDocument2, content2, MyDramaListAsianWikiText, MyDramaListCheck, MalClubText; //Make these variables global

  async function GetAllChiakiTitles() //Creates a function to GetAllChiakiTitles
  { //Starts the function
    const response = await fetch('https://api.allorigins.win/raw?url=https://chiaki.site/?/tools/watch_order/id/' + animeid); //Fetch
    const html = await response.text(); //Gets the fetch response
    const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response

    var Array = []; //Creates a new blank array
    var TextElement = newDocument.querySelectorAll("span.uk-text-muted.uk-text-small"); //Creates a variable to loop though the elements after
    for (var i = 0; i < TextElement.length; i++) { //Starts the for condition
      var TotalRawDuration = TextElement[i].textContent.split("×")[1].split("|")[0].trim(); //Creates a variable to hold the total unprocessed times
      var ALLChiakiTitles = newDocument.querySelectorAll("span.wo_title")[i].innerText; //Creates a variable to get all the anime titles on chiaki site
      var TotalEpisodes = TextElement[i].textContent.split("|")[2].match(/\d+|\?/g)[0]; //Creates a variable to hold the total episodes
      var EpisodeType = TextElement[i].textContent.split("|")[1].trim(); //Creates a variable to get the episode types
      var eps = ' eps'; //Create a variable called eps
      var Duration = ''; //Creates a blank variable
      var PerEp = ' per ep'; //Create a variable called PerEp
      if (TotalEpisodes === '1') { //If the entry has only 1 ep
        var eps = ' ' + EpisodeType; //Change the variable called eps
        var PerEp = ''; //Change the variable called PerEp
      } //Finishes the if condition
      if (EpisodeType !== 'TV') { //If the entry type isn't TV
        if (TotalEpisodes !== '1') { //If the entry doesn't have only 1 ep
          var eps = ' ' + EpisodeType + 's'; //Change the variable called eps
        } //Finishes the if condition
        var Duration = ' of ' + TotalRawDuration + PerEp; //Creates a blank variable
      } //Finishes the if condition
      Array.push(ALLChiakiTitles + ',, ' + TotalEpisodes + eps + Duration + ',' + '\n'); //Add Everything to an Array
    } //Finishes the for condition
    navigator.clipboard.writeText(Array.join('').trim()); //Copy the array to the clipboard
  } //Finishes the async GetAllChiakiTitles function

  copyButton.addEventListener("contextmenu", (e) => {
    GetAllChiakiTitles(); //Run the GetAllChiakiTitles function
    e.preventDefault(); //Don't show the right click default contextmenu
  }); //Detect the mouse right click
  copyButton.addEventListener("click", () => {
    navigator.clipboard.writeText(titleElem.textContent); //Copy the entry title with symbols
  }); //Detect the single mouse click
  copyButton.addEventListener("dblclick", () => {
    navigator.clipboard.writeText(titleElem.textContent.replace(/[^a-zA-Z0-9]+/g, " ")); //Copy the entry title without symbols
  }); //Detect the double mouse click
  copyButton.setAttribute("title", "1 Click To Copy Entry Title (+ Symbols)\n2 Clicks To Copy Entry Title (Without Symbols)\n\nRight click to Copy ALL Entry Titles In The Correct Watch Order With EP Numbers, Duration Times and Entry Types"); //Detects a mouse hover on the button and shows a explanation text
  copyButton.setAttribute("style", "cursor: pointer;margin-left: 13px;height: 10px;width: 10px;background-size: cover;display: inline-block;transform: scale(1.8);vertical-align: top;margin-top: 7px;"); //The CSS for the copy button
  titleElem.appendChild(copyButton); //Append the button close to the title element
  copyButton.style.backgroundImage = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAQAAAAm93DmAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAAAmJLR0QA/4ePzL8AAAAHdElNRQfkBhcOBQkNughZAAADCUlEQVRIx6XWS2hcVRzH8c90Jklji5qkmKipolFb2iBDQSw+KhXBRbEKLYqIiCi+4kLoJrgQfKAgiChN8UEXCr6KFVxUcFFQa6TpWDNGKUpcqKAMTU2lNdpEZ66LmTtz53FnbvQ3i5lz7r3f+/v//mcOJyWibPlrk11uNiCJin70lgnHIY909OoQ3GSvrc5KhGOFftdb53OnKCDT4G/Ey9bhmO8UpTrgAqtsMuRWcx7xt3pgpdzTcqY879cE/gJpV3nVqB1edwQ1D5X8unQJ/JWw4LIeskfKmD35msMKrtd6a2WiL6rTvBm/hfFXn5u1aKX+8kwmgrvauC3ObpPckq894wDZCjIvSyCIdinUdd52m34Z6dhPr8322hkx0aSwKed6yqUCn/jIHy09lgx7zGqDduP9msvWwM2uwQH3OhFb8HoPWk17ZAjcqEfRm2VcqzdnyVSdR5CNCjPsxVI8rlJ0LfxBu8tZxgHLSrXBcUIhMho0YUcnYHsd94ZSZHyeF1wZl2E0q3i9YpX7DVZsZFzsdjMdgNhgq+66mcC0Q0oWPO0dl+kSWONZQ0aJLutWwDVec23TbMF2OQRmzVYKHjcU6XwscGV5W2xQv75ow7KkpRrdtQb+4nF36GqYnTQpkZqBgX32N3Q/8E8yXOumUFRsNZ1NAFzOOvzPDm+0XXdz3CAlcNh7lpIDz/eS0bYm7vazT5OXHLTOL6JSuzuaHRaMuUVP25Knlpdh4jWXrOT/qdbrsLvNiwKLywOucJc7G3abeuAhLzodGQ/oxp9xwAs96ZK2Vd1gysdV3AXukXbGsbgMF/zUIaaCuervDd61DV84HOdw3gO26InFleRNV0cjRvCDJ/weB1TdQpOo5KTPPCcXTkSBqfLum+9IydbuznnUt87UnguB8+hxuYPJNikMG8D3viwPQxsh8KiT+oyZkUtwcuUi4/ootyJaUwic9oH7jNrvKwsdgIGMja7AER82XkxVM1lrwrZl/RW/8bDJxszTVE7/pxy0aNg5CaCBOfvschR15xP+BXLUxMa/tU5OAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIwLTA2LTIzVDE0OjA1OjAzKzAwOjAw5sMT7QAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMC0wNi0yM1QxNDowNTowMyswMDowMJeeq1EAAAAZdEVYdFNvZnR3YXJlAEFkb2JlIEltYWdlUmVhZHlxyWU8AAAAAElFTkSuQmCC)"; //The copy button image converted to DATA URI
  //********************************************************************************************************************************************************************
  if (window.location.pathname.split('/')[1] === 'anime') // Show the buttons to search for adaptations, and the chiaki site button only if the user is in an anime entry
  { //Starts the if function

    async function GetAnimeTitle() //Creates a function to Process and Get the Anime Title
    { //Starts the function
      const response = await fetch('https://api.allorigins.win/raw?url=https://chiaki.site/?/tools/watch_order/id/' + animeid); //Fetch
      const html = await response.text(); //Gets the fetch response
      const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
      ChiakiAnimeTitle = newDocument.querySelector("h2").innerText.split(' Watch Order')[0].replace(/[^a-zA-Z0-9]+/g, " ").trim(); //Get the anime title on the h2 element and remove the Watch Order text, and remove any symbols that the title might have, also removes the first and last whitespaces if existent
      ChiakiAnimeTitleWithSymbols = newDocument.querySelector("h2").innerText.split(' Watch Order')[0].trim(); //Get the anime title on the h2 element (with symbols) and remove the Watch Order text, also removes the first and last whitespaces if existent
      Array.from(newDocument.querySelectorAll("span.wo_title")).forEach(link => AllChiakiAnimeTitles.push(link.innerText)); //Add all anime titles of the anime franchise to the array AllChiakiAnimeTitles
      ShortestChiakiAnimeTitleWithSymbols = AllChiakiAnimeTitles.reduce((a, b) => a.length <= b.length ? a : b); //Add the Shortest Chiaki Anime Title with symbols to a variable
      ShortestChiakiAnimeTitle = ShortestChiakiAnimeTitleWithSymbols.replace(/[^a-zA-Z0-9]+/g, " "); //Remove any symbols that the title might have
      if (ChiakiAnimeTitle.match('Watch Order') !== null) //If the h2 element on chiaki.site doesn't have the anime title
      { //Starts the if condition
        ChiakiAnimeTitle = ShortestChiakiAnimeTitle; //Replace the variable ChiakiAnimeTitle contents with the variable ShortestChiakiAnimeTitle
        ChiakiAnimeTitleWithSymbols = ShortestChiakiAnimeTitleWithSymbols; //Replace the variable ChiakiAnimeTitleWithSymbols contents with the variable ShortestChiakiAnimeTitleWithSymbols contents
      } //Finishes the if condition

      response2 = await fetch("https://api.allorigins.win/raw?url=https://mydramalist.com/search?q=" + ChiakiAnimeTitle); //Fetch
      html2 = await response2.text(); //Gets the fetch response
      newDocument2 = new DOMParser().parseFromString(html2, 'text/html'); //Parses the fetch response
      content2 = newDocument2.querySelector("div.col-lg-8.col-md-8"); //Get the results page on MyDramaList

      if (newDocument2.body.innerText.search(' found for: ') > -1) //Check if MyDramaList returned any results or not
      { //Starts the if condition
        MyDramaListAsianWikiText = ',AsianWiki and MyDramaList'; //Display to the user that MyDramaList website will be opened if Ok is clicked
        MyDramaListCheck = '👍 Found on MyDramaList.'; //Display the confirmation that the anime has adaptations found on MyDramaList
      } //Finishes the if condition
      else { //Starts the else condition
        MyDramaListAsianWikiText = ' and AsianWiki'; //Display to the user that only the imdb and the AsianWiki websites will be opened if Ok is clicked
        MyDramaListCheck = '✖ NOT Found on MyDramaList.'; //Display the confirmation that the anime doesn't have any adaptations found on MyDramaList
      } //Finishes the else condition
    } //Finishes the async function
    GetAnimeTitle(); //Call the GetAnimeTitle function

    findButton.addEventListener("click", () => { //Detect the mouse click and search for the anime title
      async function CheckWithAMALClub() //Creates a function to Check With A MAL Club
      { //Starts the function
        const response = await fetch('https://myanimelist.net/clubs.php?cid=5450'); //Fetch
        const html = await response.text(); //Gets the fetch response
        const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
        var content = newDocument.querySelector("#content > table > tbody > tr > td:nth-child(2) > div"); //Get the Anime titles related to the MALClub

        newDocument.body.innerText.search(ChiakiAnimeTitleWithSymbols) > -1 ? MalClubText = '👍 Found on this MAL Club https://bit.ly/38KZxwH.' : MalClubText = '✖ NOT found on this MAL Club https://bit.ly/38KZxwH'; //If the title is found on the MALClub, display the confirmation whether or not the anime has adaptations found on the MALClub

        if (confirm('Anime Title: ' + ChiakiAnimeTitle + '\n\n' + MyDramaListCheck + '\n' + MalClubText + '\n\nDo you want to open IMDB' + MyDramaListAsianWikiText + ' to confirm that information and get more detailed info?')) //Show the confimation alert box text
        { //Starts the if condition
          window.open("https://www.imdb.com/find?q=" + ChiakiAnimeTitle + "&s=tt&ref_=fn_al_tt_mr", "_blank"); //Open IMDB on a new tab
          window.open("http://asianwiki.com/index.php?title=Special%3ASearch&search=" + ChiakiAnimeTitle, "_blank"); //Open AsianWiki on a new tab
          if (MyDramaListCheck.match('NOT') === null) {
            window.open("https://mydramalist.com/search?q=" + ChiakiAnimeTitle, "_blank");
          } //Open MyDramaList on a new tab only if any results were found on the website
        } //Finishes the if condition
      } //Finishes the async function
      CheckWithAMALClub(); //Calls the function CheckWithAMALClub
    }); //Finishes the advent listener
    findButton.setAttribute("title", "Search for Live-Actions/Doramas"); //Detects a mouse hover on the button and show the text Find Live-Actions
    findButton.setAttribute("style", "cursor: pointer;margin-left: 15px;height: 10px;width: 10px;background-size: cover;display: inline-block;transform: scale(1.8);vertical-align: top;margin-top: 7px;"); //The CSS for the findButton
    titleElem.appendChild(findButton); //Append the button close to the title element
    findButton.style.backgroundImage = "url(data:image/png;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dw0Zd65WyaAAAAJXRFWHRkYXRlOmNyZWF0ZQAyMDIwLTA2LTIzVDE0OjE5OjI4KzAwOjAwfVN/JAAAACV0RVh0ZGF0ZTptb2RpZnkAMjAyMC0wNi0yM1QxNDoxOToyOCswMDowMAwOx5gAAAAASUVORK5CYII=)"; //The find button image converted to DATA URI
    //********************************************************************************************************************************************************************
    chiakiButton.setAttribute("href", "https://chiaki.site/?/tools/watch_order/id/" + animeid); //Detects the mouse click, and open chiaki.site on a new tab to show all the related anime entries on MAL on the correct watch order for the anime franchise
    chiakiButton.setAttribute("target", "_blank"); //Specifies that chiaki.site should be opened on a new tab
    chiakiButton.setAttribute("title", "Find Related Entries + Correct Watch Order"); //Detects a mouse hover on the button and show the text Find Related Entries + Correct Watch Order
    chiakiButton.setAttribute("style", "margin-left: 15px;height: 10px;width: 10px;background-size: cover;display: inline-block;transform: scale(1.8);vertical-align: top;margin-top: 7px;"); //The CSS for the chiakiButton
    titleElem.appendChild(chiakiButton); //Append the button close to the title element
    chiakiButton.style.backgroundImage = "url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAAUCAMAAAC6V+0/AAAAeFBMVEUAAADfceLecePYcefycdTMcfHZcefPce7tcdfQce3tcdffceLQce3tcdfeceLmcdziceDycdPLcfDYceflcd3KcfHycdPzcdPUce3tcdricePxtPDlkev0w/Pjg+ftf97ae+v10fboqvLvourvm+ftieHkm+/ah+6xZFdBAAAAGHRSTlMAFypl7u3s3t21tYlzc/Dv6MPCwsKJiWWHdugpAAAA1klEQVQY013Q2XLCMAwFUMehCQkJe4sW2wlZyv//YWVVzAD3yT5zNV6cxndNDVA3nXfPFOX5CzTVpSzMvpWMd8WHERDtVUs1U8mxlDPOLz3N1bvuvziOMIZAKREeetcAPCZmDpAip3kZCFtXg1Q4hpHCPXKcecCtk9HfKd6nKaWMLIgZH7kZkjRlIYYynrtMRIGXNfKCMt4YSuZZWMZb11UAlJIYDuuKOOCmd/5id8ZnTl6eWb3b5pY/ZLdXI7OfwqkeDczsk68Ho9NNzOL7div3a3uv2z/lrx6iZfibGQAAAABJRU5ErkJggg==)";
  } //The copy button image converted to DATA URI
})(); //Finish the whole function