MAL Profile Stats With Percentages + Hours

MAL Percentages + Hours

目前為 2020-07-25 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name MAL Profile Stats With Percentages + Hours
// @namespace http://tampermonkey.net/
// @version 0.1
// @description MAL Percentages + Hours
// @author Only_Brad (& commented by hacker09)
// @match https://myanimelist.net/profile/*
// @run-at document-end
// @grant GM_addStyle
// ==/UserScript==

// Functions to select the days txt and day numbers to convert then to txt hours and numbers in hours later
(function(){
GM_addStyle(".profile .user-statistics .stats-status{width: 200px;}");
const days = document.querySelector(".di-tc.al.pl8.fs12.fw-b"),
hours = days.cloneNode(true),
hoursText = hours.querySelector("span"),
hoursValueNode = hoursText.nextSibling,
hoursValue = parseFloat(hoursValueNode.textContent.replace(/,/g,""));

// Add the symbol // on the beginning the 2 lines below "disable" the total hours,then you can have just the mal percentages feature
hoursText.textContent = "Hours: ";
hoursValueNode.textContent = (hoursValue * 24).toFixed(1);
days.insertAdjacentElement("afterend",hours);

// Functions to select all the animes stats and the Total stats
const total = parseInt(document.querySelector(".stats-data.fl-r span:nth-child(2)").textContent.replace(/,/g,""));
const [watching,completed,onHold,dropped,planToWatch] = document.querySelectorAll(".di-ib.fl-r.lh10");

// Functions to add the percentage after the total number of each watching,completed,onHold,dropped,planToWatch
[watching,completed,onHold,dropped,planToWatch].forEach(addPercentage);

// Functions that do the math
function getPercentage(node) {
const value = parseInt(node.textContent.replace(/,/g,""));
if(total === 0) return "0.00";
return (value*100/total).toFixed(2);
}

// Functions to show and append the scores after each watching,completed,onHold,dropped,planToWatch
function addPercentage(node) {
const percentage = getPercentage(node);
node.textContent = `${node.textContent} (${percentage}%)`;
}
})()