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-25 提交的版本。查看 最新版本

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

(function() {
    'use strict';
if (document.querySelector("div.score-label.score-na") !== null) {

  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

    const votes = [...newDocument.querySelectorAll(".score-stats td")].map(row => row.textContent)
    const scoreDictionary = {}
    for(let i=1;i<votes.length;i+=2) {
      const vote = votes[i];
      const score = votes[i-1];
      scoreDictionary[score] = vote;
    }

    for(let i in scoreDictionary)
    scoreDictionary[i] = Number(scoreDictionary[i].match(/.*\((\d+) votes?\)/)[1]);
    const totalVotes = Object.values(scoreDictionary).reduce( (acc, val) => acc + val );
    let average = 0;

    for(let i in scoreDictionary)
    average += scoreDictionary[i] * i;
    var result = average /= totalVotes;

    document.querySelector("div.score-label.score-na").innerText = result.toFixed(2); //Show the Average Score results
    document.querySelectorAll("div.fl-l.score")[0].dataset.user = totalVotes+' users';
  } //Finishes the async function

GetStats(); //Starts the function GetStats

 } //Finishes the if statement
})();

QingJ © 2025

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