ALink

Adds AniList links to mangadex manga pages

当前为 2019-01-01 提交的版本,查看 最新版本

// ==UserScript==
// @name ALink
// @namespace Morimasa
// @author Morimasa
// @description Adds AniList links to mangadex manga pages
// @match https://mangadex.org/title/*
// @match https://mangadex.org/manga/*
// @version 0.2
// ==/UserScript==

const mal = document.querySelector('a[href^="https://myanimelist.net"]')
let query = ''
let vars = {}
const title = document.getElementsByClassName("card-header")[0].childNodes[2].textContent;

if (mal){
  query = `query($mal:Int){Media(idMal:$mal,type:MANGA){id}}`;
  vars = {"mal": parseInt(mal.href.split('/').pop())};
}
else{
  const isOneshot = document.querySelector('.badge[href$="/genre/21"]')
  query = `query($s:String){Media(search:$s,format:${isOneshot?'ONE_SHOT':'MANGA'},type:MANGA){id}}`;
  vars = {"s": title};
}

const handle = data => {
  if (data["data"]["Media"])
    document.getElementsByClassName("list-inline")[3].innerHTML+=`<li class="list-inline-item"><a rel="noopener noreferrer" target="_blank" href="https://anilist.co/manga/${data["data"]["Media"]["id"]}"><img src="https://anilist.co/img/icons/favicon-32x32.png" height=16>AniList</a></li>`;
  else
    console.log(`ALink: "${title}" not found!`)
}

const fetch_options = {
    method: 'POST',
    body: JSON.stringify({query: query, variables: vars}),
    headers: new Headers({
        'Content-Type': 'application/json'
    })
};
fetch('https://graphql.anilist.co/', fetch_options)
.then(res => res.json())
.then(res => handle(res))
.catch(error => console.error(`ALink: Error - ${error}`));

QingJ © 2025

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