🏠 Home 

Greasy Fork is available in English.

MAL Summary+Profile Stats With Percentages + Hours

See your profile stats in % + Hours, and see the Summary Stats in %


Installer dette script?
Skaberens foreslåede script

Du vil måske også kunne lide Generate a List With The Animes/Mangas Titles that were Re-Watched/Re-Read


Installer dette script
  1. // ==UserScript==
  2. // @name MAL Summary+Profile Stats With Percentages + Hours
  3. // @namespace http://tampermonkey.net/
  4. // @version 6
  5. // @description See your profile stats in % + Hours, and see the Summary Stats in %
  6. // @author Only_Brad (& commented by hacker09)
  7. // @include /^https:\/\/myanimelist\.net\/(anime|manga)\/[\d]+\/.*\/stats/
  8. // @match https://myanimelist.net/profile/*
  9. // @exclude https://myanimelist.net/*/*/clubs
  10. // @exclude https://myanimelist.net/*/*/reviews
  11. // @exclude https://myanimelist.net/*/*/friends
  12. // @exclude https://myanimelist.net/*/*/recommendations
  13. // @icon https://www.google.com/s2/favicons?domain=myanimelist.net
  14. // @run-at document-end
  15. // @grant GM_addStyle
  16. // ==/UserScript==
  17. // Functions to select the days txt and day numbers to convert then to txt hours and numbers in hours later
  18. (function() {
  19. if (location.href.match('profile') !== null) //If the current url is the profile of some user
  20. { //Starts the if condition
  21. GM_addStyle(".profile .user-statistics .stats-status{width: 200px;}");
  22. document.head.insertAdjacentHTML('afterend', '<style>span.di-ib.fl-r.lh10 {position: absolute!important; text-indent: 10px!important;}</style>'); //Fixes new dark mode bug
  23. const days = document.querySelector(".di-tc.al.pl8.fs12.fw-b"),
  24. hours = days.cloneNode(true),
  25. hoursText = hours.querySelector("span"),
  26. hoursValueNode = hoursText.nextSibling,
  27. hoursValue = parseFloat(hoursValueNode.textContent.replace(/,/g, ""));
  28. // Add the symbol // On the beginning the 2 lines below "disable" the total hours,then you can have just the mal percentages feature
  29. hoursText.textContent = "Hours: ";
  30. hoursValueNode.textContent = (hoursValue * 24).toFixed(1);
  31. days.insertAdjacentElement("afterend", hours);
  32. // Functions to select all the animes stats and the Total stats
  33. const total = parseInt(document.querySelector(".stats-data.fl-r span:nth-child(2)").textContent.replace(/,/g, ""));
  34. const [watching, completed, onHold, dropped, planToWatch] = document.querySelectorAll(".di-ib.fl-r.lh10");
  35. // Functions to add the percentage after the total number of each watching,completed,onHold,dropped,planToWatch
  36. [watching, completed, onHold, dropped, planToWatch].forEach(addPercentage);
  37. // Functions that do the math
  38. function getPercentage(node) {
  39. const value = parseInt(node.textContent.replace(/,/g, ""));
  40. if (total === 0) return "0.00";
  41. return (value * 100 / total).toFixed(2);
  42. }
  43. // Functions to show and append the scores after each watching,completed,onHold,dropped,planToWatch
  44. function addPercentage(node) {
  45. const percentage = getPercentage(node);
  46. node.textContent = `${node.textContent} (${percentage}%)`;
  47. }
  48. } //Finishes the if condition
  49. else //If the user is on the summary page
  50. { //Starts the else condition
  51. const [, , , watching, completed, onHold, dropped, planToWatch, total] = document.querySelectorAll("#content > table > tbody > tr > td:nth-child(2) > div.js-scrollfix-bottom-rel > div");
  52. const totalValue = getValue(total);
  53. [watching, completed, onHold, dropped, planToWatch].forEach(addPercentage);
  54. //Uncomment the below code to swap "Watching" and "Completed" positions
  55. //watching.before(completed);
  56. function getValue(node) {
  57. const text = node.querySelector("span");
  58. return parseInt(text.nextSibling.textContent.replace(/,/g, ""));
  59. }
  60. function getPercentage(node) {
  61. if (totalValue === 0) return "0.00";
  62. const value = getValue(node);
  63. return (value * 100 / totalValue).toFixed(2);
  64. }
  65. function addPercentage(node) {
  66. const text = node.querySelector("span");
  67. const valueNode = text.nextSibling;
  68. const percentage = getPercentage(node);
  69. valueNode.textContent = `${valueNode.textContent} (${percentage}%)`;
  70. addBar(node, percentage);
  71. }
  72. function addBar(node, percentage) {
  73. const percentageText = convertTextNodeToSpan(node);
  74. percentageText.style = "font-weight: normal";
  75. const textNode = node.querySelector(".dark_text");
  76. textNode.appendChild(percentageText);
  77. const bar = document.createElement("div");
  78. bar.setAttribute("class", "updatesBar");
  79. bar.style = `display: block; height: 15px; width: ${percentage}%;`;
  80. textNode.after(bar);
  81. }
  82. function convertTextNodeToSpan(node) {
  83. for (const child of node.childNodes) {
  84. if (child.nodeType === Node.TEXT_NODE) {
  85. const text = child.textContent;
  86. child.remove();
  87. const span = document.createElement("span");
  88. span.textContent = text;
  89. node.appendChild(span);
  90. return span;
  91. }
  92. }
  93. }
  94. } //Finishes the else condition
  95. })()