Show The Average Score For Animes/Mangas Instead Of N/A

Use this script to see the average score of unpopular animes/mangas that have unweighted scores "N/A" on MAL.

目前為 2020-10-21 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Show The Average Score For Animes/Mangas Instead Of N/A
// @namespace    AverageScore
// @version      0.1
// @description  Use this script to see the average score of unpopular animes/mangas that have unweighted scores "N/A" on MAL.
// @author       hacker09
// @match        https://myanimelist.net/anime/*
// @match        https://myanimelist.net/manga/*
// @match        https://myanimelist.net/anime.php?id=*
// @match        https://myanimelist.net/manga.php?id=*
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
    'use strict';
if (document.querySelector("div.score-label.score-na") !== null) {
  var statscontent, i;
  async function GetStats() //Creates a function to get the stats
  { //Starts the function
    var url = document.querySelector("a[href*='stats']").href;
    const response = await fetch(url); //Fetch the stats page
    const html = await response.text(); //Gets the fetch response
    const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
    statscontent = newDocument.querySelector("table.score-stats").textContent; //Creates a variable to hold the stats numbers
  } //Finishes the async function

  async function Start() { //Starts the function
    await GetStats(); //Starts the function
    //Start the math to process the variable statscontent TextContent into actual usable numbers
    var raw = statscontent; //Add the variable statscontent TextContent into the variable named raw
    raw = raw.split("(");
    raw.shift();
    for (i = 0; i < 10; i++) {
      raw[i] = raw[i].split(" votes");
      raw[i].pop();
    }
    var stats = [];
    for (i = 0; i < 10; i++) {
      stats.push(parseInt(raw[i].pop()));
    }
    //calculate the amount of votes
    var votes = 0;
    for (i = 0; i < 10; i++) {
      votes = votes + stats[i];
    }
    //calculate the average
    var result = 0;
    for (i = 0; i < 10; i++) {
     result = result + stats[i] * (10 - i);
    }
    result = result / votes;
    document.querySelector("div.score-label.score-na").innerText = result.toFixed(2); //Show the Average Score results
  } //Finishes the function Start
  Start(); //Starts the function
} //Finishes the if statement
})();