Greasy Fork 支持简体中文。

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-11-06 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Show The Average Score For Animes/Mangas Instead Of N/A
// @namespace    AverageScore
// @version      0.2
// @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 stats = [];
    var votes = 0;
    var result = 0;
    var raw = document.querySelector("table.score-stats").textContent; //Creates a variable to hold the stats numbers; //Add the variable statscontent TextContent into the variable named raw
    raw = raw.split("(");
    raw.shift();
    for (i = 0; i < document.querySelectorAll("div.updatesBar").length; i++) {
      raw[i] = raw[i].split(" votes");
      raw[i].pop();
      stats.push(parseInt(raw[i].pop()));
      votes = votes + stats[i]; //calculate the amount of votes
     result = result + stats[i] * (document.querySelectorAll("div.updatesBar").length - i); //calculate the average
    }

    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
})();