Finish Airing Date - MAL

Calculate the expected finished airing date for anime entries.

当前为 2023-12-13 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Finish Airing Date - MAL
  3. // @namespace https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
  4. // @version 1
  5. // @description Calculate the expected finished airing date for anime entries.
  6. // @author hacker09
  7. // @match https://myanimelist.net/anime/*
  8. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
  9. // @run-at document-end
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var startDateElement = [...[...document.querySelectorAll("h2")].find(h2 => h2.textContent === "Information").parentNode.querySelectorAll("div")].find(info => info.innerText.includes("Aired")).querySelector("span"); //Get the start date from the page
  16. if (startDateElement.parentNode.textContent.match(/\?/) !== null && document.querySelector("#curEps").innerText !== '?') { //If the finished date is unkown and the total entry eps are known
  17. var startDateMatch = startDateElement.parentNode.textContent.match(/(\w{3})\s(\d{1,2}),\s(\d{4})/); //Save the start date
  18. var month = {'Jan': 1, 'Feb': 2, 'Mar': 3, 'Apr': 4, 'May': 5, 'Jun': 6, 'Jul': 7, 'Aug': 8, 'Sep': 9, 'Oct': 10, 'Nov': 11, 'Dec': 12}[startDateMatch[1]]; //Convert start month to number
  19. var startDate = new Date(parseInt(startDateMatch[3]), month - 1, parseInt(startDateMatch[2])); //Save start date Year, month, day
  20. var expectedFinishedAiringDate = new Date(startDate.getTime() + parseInt(document.querySelector("#curEps").innerText) * 7 * 24 * 60 * 60 * 1000); //Calculate the expected finished date
  21.  
  22. startDateElement.parentNode.className += ' dark_text'; //Make the text bold
  23. startDateElement.nextSibling.textContent = startDateElement.nextSibling.textContent.replace(/\?/g, ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"][expectedFinishedAiringDate.getMonth()] + ' ' + expectedFinishedAiringDate.getDate() + ', ' + expectedFinishedAiringDate.getFullYear()); //Replace ? with the finished and formated date
  24. } //Finishes the if condition
  25. })();