Friends Average Score - MAL

Show all your friends weighted score for an entry.

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Friends Average Score - MAL
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      10
// @description  Show all your friends weighted score for an entry.
// @author       hacker09
// @include      /^https:\/\/myanimelist\.net\/(anime|manga)(id=)?(\.php\?id=)?\/?\d+\/?(?!.*\/).*(\?q=.*&cat=anime|manga)?$/
// @icon         https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
// @run-at       document-end
// @grant        none
// ==/UserScript==

(async function() {
  'use strict';
  document.querySelector("div.fl-l.score").style.cursor = 'pointer'; //Make the score look like it's clickable
  document.querySelector("div.fl-l.score").onclick = async function GetScores() { //Creates a new function to run when the mouse is hovering the page
    var Average; //Global Variable
    var array = []; //Create a new array
    var nextpagenum = 0; //Create a variable to hold the page number
    const increaseby = 75; //Create a variable to Increase the list page number

    while (true) { //Fetch until there's no next page
      const response = await fetch(document.querySelector("a[href*='stats']").href.split('?')[0] + '?show=' + nextpagenum); //Fetch
      const html = await response.text(); //Gets the fetch response
      const newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
      nextpagenum += increaseby; //Increase the next page number
      newDocument.querySelectorAll("table.table-recently-updated > tbody > tr > td:nth-child(2)").forEach(async function(el) { //For each friend score
        if (el.innerText.match(/\d+/) !== null) //If the score is not = -
        { //Start the if condition
          array.push(parseInt(el.innerText.match(/\d+/)[0])); //Add each score to an array
          var ScoresTotal = array.filter(Boolean).map(i => Number(i)).reduce((a, b) => a + b); //Sum all scores
          Average = (ScoresTotal / array.length).toFixed(2); //Divide all scores by total amount of scores and convert the average to show numbers only up to 2 decimal places
        } //Finishes the if condition
      }); //Finishes the for each loop
      document.querySelector("div.fl-l.score").title = 'Average based on 0 Friend scores.'; //Show the amount of friends friends score
      if (response.status === 404) { //If the next page does not exist
        if (Average !== undefined) //If the Average is not = undefined
        { //Start the if condition
          document.querySelector("div.fl-l.score").dataset.title += '(' + Average + ')'; //Show the friends entry average
          document.querySelector("div.fl-l.score").title = 'Average based on ' + array.length + ' Friend scores.'; //Show the amount of friends friends score
        } //Finishes the if condition
        return; //End the fetching loop
      } //Finishes the if condition
      await new Promise(resolve => setTimeout(resolve, 600)); //Wait 600 ms to fetch the next page
    } //Finishes the while condition
  }; //Finishes the onmousemove event listener
})();