Links to titles - MAL

Shows entry and topic titles instead of full link urls.

Mint 2022.08.07.. Lásd a legutóbbi verzió

// ==UserScript==
// @name         Links to titles - MAL
// @namespace    https://greasyfork.org/en/users/670188-hacker09?sort=daily_installs
// @version      6
// @description  Shows entry and topic titles instead of full link urls.
// @author       hacker09
// @match        https://myanimelist.net/profile/*
// @match        https://myanimelist.net/clubs.php?cid=*
// @match        https://myanimelist.net/forum/?topicid=*
// @match        https://myanimelist.net/comments.php?id*
// @match        https://myanimelist.net/clubs.php?id=*&action=view&t=comments&show=*
// @icon         https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
// @connect      api.myanimelist.net
// @grant        GM.xmlHttpRequest
// @run-at       document-end
// ==/UserScript==

(function() {
  'use strict';
  [...document.querySelectorAll('a')].filter(a => a.textContent.match(/myanimelist.net\/(anime|manga|forum)\//)).forEach(async function(el, index) { //For each entry url on the page
    if (el.innerText.match(/(?<=\d+\/)[^\/".]+/) === null && el.innerText.match(/\/forum\//) === null) //If the link doesn't have the entry name on it
    { //Starts the if condition
      setTimeout(async function() { //Starts the setimeout function
        const EntryTitle = await new Promise((resolve) => GM.xmlHttpRequest({ //Starts the xmlHttpRequest
          responseType: 'json',
          url: `https://api.myanimelist.net/v2/${el.href.split('/')[3]}/${el.href.match(/\d+/)[0]}?fields=title`,
          headers: {
            "x-mal-client-id": "8ef0267fd86a187d479e6fcd7e1bb42a"
          },
          onload: r => resolve(r.response.title)
        })); //Finishes the xmlHttpRequest
        el.innerText = EntryTitle; //Convert the link to EntryTitle
      }, index * 1000); //Finishes the setimeout function
    } //Finishes the if condition

    if (el.innerText.match(/(?<=\d+\/)[^\/".]+/) !== null && el.innerText.match(/\/forum\//) === null) //If the link already has the entry name on it
    { //Starts the if condition
      el.innerText = el.innerText.match(/(?<=\d+\/)[^\/".]+/)[0].replaceAll('_', ' '); //Convert the link to title
    } //Finishes the if condition

    if (el.innerText.match(/\/forum\//) !== null) //If it's a forum link
    { //Starts the if condition
      var PostId = ''; //Creates a new global variable
      setTimeout(async function() { //Starts the setimeout function
        const Topic = await new Promise((resolve) => GM.xmlHttpRequest({ //Starts the xmlHttpRequest
          responseType: 'json',
          url: 'https://api.myanimelist.net/v2/forum/topic/' + el.href.match(/\d+/)[0] + '?limit=100',
          headers: {
            "x-mal-client-id": "8ef0267fd86a187d479e6fcd7e1bb42a"
          },
          onload: r => resolve(r.response)
        })); //Finishes the xmlHttpRequest
        Topic.data.posts.forEach(Mid => Mid.id === parseInt(el.href.match(/\d+/g).pop()) ? PostId = ` (#${Mid.number})` : ''); //Get the post ID
        el.innerText = Topic.data.title + PostId; //Convert the link to EntryTitle
      }, index * 1000); //Finishes the setimeout function
    } //Finishes the if condition
  }); //Finishes the for each condition
})();