Show Anime Duration With Seconds

This script will show the Duration Time with seconds for all animes.

当前为 2021-03-27 提交的版本,查看 最新版本

// ==UserScript==
// @name         Show Anime Duration With Seconds
// @namespace    DurationWithSeconds
// @version      0.5
// @description  This script will show the Duration Time with seconds for all animes.
// @author       hacker09
// @include      /^https:\/\/myanimelist\.net\/anime\/[\d]+(\/.*)?/
// @icon         https://www.google.com/s2/favicons?domain=myanimelist.net
// @run-at       document-end
// ==/UserScript==
(function() {
  'use strict';
  var animeid = location.pathname.match(/\d+/)[0]; //Detect the anime id
  if (document.querySelector("#malLogin") === null) {
    runscript();
  } else {
    console.log('Not Logged In!');
  } //Detect the username to know if the user is logged in or not,if not then the script won't work,so it won't run
  function runscript() {
    (async function runscript() {
      const response = await fetch('https://myanimelist.net/dbchanges.php?aid=' + animeid + '&t=duration'); //Get the duration with seconds of the anime
      const html = await response.text(); //Gets the fetch response
      const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
      const DurationWithSeconds = newDocument.querySelectorAll("input.inputtext")[1].defaultValue; //Select the duration with seconds value, and creates the variable DurationWithSeconds to hold this value
      var hours = DurationWithSeconds.split(':')[0]; //Variable to hold the hours value
      var mins = DurationWithSeconds.split(':')[1]; //Variable to hold the minutes value
      var secs = DurationWithSeconds.split(':')[2]; //Variable to hold the seconds value

      if (hours !== '00') {
        var Duration = hours + ' hr. ' + mins + ' min. ' + secs + ' sec.';
      } //If hours is NOT = 00, show hours+minutes+seconds
      else if (hours === '00' && mins === '00') {
        var Duration = ' ' + secs + ' sec.';
      } //If hours and minutes are = 00, show only the seconds (keep as it is)
      else {
        var Duration = mins + ' min. ' + secs + ' sec.';
      } //If hours is = 00, but minutes is NOT = 00, show only the minutes with seconds

      function findTheInformationheader() {
        const headers = [...document.querySelectorAll("h2")]; //Select all h2 elements on MAL
        return headers.find(h2 => h2.textContent === "Information");
      } //Find the h2 element that has the text Information

      function findTheDurationText() {
        const allInfo = [...findTheInformationheader().parentNode.querySelectorAll("div")]; //Select all divs inside the Information h2 element
        return allInfo.find(info => info.innerText.includes("Duration"));
      } //Find the Duration text that's inside the information h2 element
      findTheDurationText().querySelector("span").nextSibling.textContent = ' ' + Duration + ' per ep.'; //Change the text content of the Duration: Element
    }()); //Finishes the async function
  } //Finishes the function
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址