Greasy Fork

Greasy Fork is available in English.

MALScore

Adds MyAnimeList link and score to AniList anime and manga pages

当前为 2018-12-25 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name MALScore
// @namespace Ract
// @author Ract
// @description Adds MyAnimeList link and score to AniList anime and manga pages
// @match https://anilist.co/anime/*
// @match https://anilist.co/manga/*
// @require      http://greasyfork.icu/scripts/5679-wait-for-elements/code/Wait%20For%20Elements.js?version=147465
// @grant GM_xmlhttpRequest
// @version 1
// ==/UserScript==
// Thanks to http://greasyfork.icu/en/scripts/5890-kitsu-mal-rating for code reference
var SCRIPT_NAME = 'MAL Score';


var Util = {
    log: function() {
        var args = [].slice.call(arguments);
        args.unshift('%c' + SCRIPT_NAME + ':', 'font-weight: bold;color: #233c7b;');
        console.log.apply(console, args);
    },
    q: function(query, context) {
        return (context || document).querySelector(query);
    },
    qq: function(query, context) {
        return [].slice.call((context || document).querySelectorAll(query));
    }
};

function getRating(malURL,cb){
    GM_xmlhttpRequest({
        method: 'GET',
        url: malURL,
        onload: function(response) {
          try {
            var tempDiv = document.createElement('div');
            tempDiv.innerHTML = response.responseText;

            var sidebar = Util.q('#content > table > tbody > tr > td.borderClass', tempDiv);
            var rating = Util.q('span[itemprop="ratingValue"]', sidebar);
            var headerNum;

            if (Util.q('h2.mt8', sidebar)) headerNum = 4;
            else headerNum = 3;

            if (rating) {
              rating = rating.innerText;
            } else {
              var score = Util.q('h2:nth-of-type(' + headerNum + ') + div', sidebar).innerText.replace(/[\n\r]/g, '');
              if (score.match(/Score:\s+N\/A/)) {
                rating = null;
              } else {
                rating = score.match(/[0-9]{1,2}\.[0-9]{2}/)[0];
              }
            }
            Util.log(rating)
            cb(rating);
          } catch (err) {
            Util.log('Failed to parse MAL page');
          }
        }
        });
}
waitForUrl(function() {
GM_xmlhttpRequest({
    method: "POST",
    url: "https://graphql.anilist.co",
    data: JSON.stringify({
          query: `query ($id: Int,$type:MediaType) {
                      Media (id: $id, type:$type) {
                          idMal
                      }
                  }`,
          variables: {
            "id": window.location.pathname.split("/")[2],
            "type": window.location.pathname.split("/")[1].toUpperCase()
          }
      }),
    headers: {
        "Content-Type": "application/json"
    },
    onload: function(response) {
        var type = window.location.pathname.split("/")[1].toLowerCase();
        var malID=JSON.parse(response.responseText)["data"]["Media"]["idMal"];
        var malURL = "https://myanimelist.net/" + type+ "/"+ malID;
        //Util.log(malURL);
        getRating(malURL,function(rating) {
            //Util.log("rating"+rating);
            waitForElems({
              sel: '.data:not(#malscorebox)',
              stop: true,
              onmatch: function() {
                  //Util.log("ratingfound"+rating);
                  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>`
              }
            });
        });

    }
});
});