MALScore

Adds MyAnimeList link and score to AniList anime and manga pages

  1. // ==UserScript==
  2. // @name MALScore
  3. // @namespace Ract
  4. // @author Ract
  5. // @description Adds MyAnimeList link and score to AniList anime and manga pages
  6. // @match https://anilist.co/*
  7. // @require https://gf.qytechs.cn/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=147465
  8. // @grant GM_xmlhttpRequest
  9. // @version 2
  10. // ==/UserScript==
  11. // Thanks to https://gf.qytechs.cn/en/scripts/5890-kitsu-mal-rating for code reference
  12. var SCRIPT_NAME = 'MAL Score';
  13.  
  14.  
  15. var Util = {
  16. log: function() {
  17. var args = [].slice.call(arguments);
  18. args.unshift('%c' + SCRIPT_NAME + ':', 'font-weight: bold;color: #233c7b;');
  19. console.log.apply(console, args);
  20. },
  21. q: function(query, context) {
  22. return (context || document).querySelector(query);
  23. },
  24. qq: function(query, context) {
  25. return [].slice.call((context || document).querySelectorAll(query));
  26. }
  27. };
  28.  
  29. function getRating(malURL,cb){
  30. GM_xmlhttpRequest({
  31. method: 'GET',
  32. url: malURL,
  33. onload: function(response) {
  34. try {
  35. var tempDiv = document.createElement('div');
  36. tempDiv.innerHTML = response.responseText;
  37.  
  38. var sidebar = Util.q('#content > table > tbody > tr > td.borderClass', tempDiv);
  39. var rating = Util.q('span[itemprop="ratingValue"]', sidebar);
  40. var headerNum;
  41.  
  42. if (Util.q('h2.mt8', sidebar)) headerNum = 4;
  43. else headerNum = 3;
  44.  
  45. if (rating) {
  46. rating = rating.innerText;
  47. } else {
  48. var score = Util.q('h2:nth-of-type(' + headerNum + ') + div', sidebar).innerText.replace(/[\n\r]/g, '');
  49. if (score.match(/Score:\s+N\/A/)) {
  50. rating = null;
  51. } else {
  52. rating = score.match(/[0-9]{1,2}\.[0-9]{2}/)[0];
  53. }
  54. }
  55. Util.log(rating)
  56. cb(rating);
  57. } catch (err) {
  58. Util.log('Failed to parse MAL page');
  59. }
  60. }
  61. });
  62. }
  63. waitForUrl(function() {
  64. GM_xmlhttpRequest({
  65. method: "POST",
  66. url: "https://graphql.anilist.co",
  67. data: JSON.stringify({
  68. query: `query ($id: Int,$type:MediaType) {
  69. Media (id: $id, type:$type) {
  70. idMal
  71. }
  72. }`,
  73. variables: {
  74. "id": window.location.pathname.split("/")[2],
  75. "type": window.location.pathname.split("/")[1].toUpperCase()
  76. }
  77. }),
  78. headers: {
  79. "Content-Type": "application/json"
  80. },
  81. onload: function(response) {
  82. var type = window.location.pathname.split("/")[1].toLowerCase();
  83. var malID=JSON.parse(response.responseText)["data"]["Media"]["idMal"];
  84. var malURL = "https://myanimelist.net/" + type+ "/"+ malID;
  85. //Util.log(malURL);
  86. getRating(malURL,function(rating) {
  87. //Util.log("rating"+rating);
  88. waitForElems({
  89. sel: '.data:not(#malscorebox)',
  90. stop: true,
  91. onmatch: function() {
  92. //Util.log("ratingfound"+rating);
  93. document.getElementsByClassName("data")[0].innerHTML+=`<div id="malscorebox" data-v-ead17872="" class="data-set"><div data-v-ead17872="" class="type">MAL Score</div> <div id="malscore" data-v-ead17872="" class="value"><a rel="noopener noreferrer" href="${malURL}">${rating}</a></div></div>`
  94. }
  95. });
  96. });
  97.  
  98. }
  99. });
  100. });

QingJ © 2025

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