Affinity to You

Shows the "Affinity to You" that all users who have commented on any topic on MAL have with you!

Από την 24/03/2021. Δείτε την τελευταία έκδοση.

// ==UserScript==
// @name         Affinity to You
// @namespace    AffinityShow
// @version      0.2
// @description  Shows the "Affinity to You" that all users who have commented on any topic on MAL have with you!
// @author       hacker09
// @match        https://myanimelist.net/forum/?topicid=*
// @icon         https://www.google.com/s2/favicons?domain=myanimelist.net
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
  'use strict';
  var UserNames = []; //Creates a new blank global array
  Array.from(document.querySelectorAll("[id*=messageuser] > a > strong")).forEach(UserName => UserNames.push(UserName.innerText)); //Store all the topic User Names
  UserNames = [...new Set(UserNames)]; //Remove the duplicated usernames of the array
  UserNames = UserNames.filter(v => v !== document.querySelector("a.header-profile-link").innerText); //Remove the script user username of the array if the script user also commented on the topic
  UserNames = UserNames.filter(v => v !== 'removed-user'); //Remove the 'removed-user' username of the array (if existent on the topic page)

  var Affinities = []; //Creates a new blank global array
  var AllComments = document.querySelectorAll("td.forum_boardrow2 > div"); //Get all comments user images,names and info
  var UserName = document.querySelectorAll("[id*=messageuser] > a > strong"); //Get all usernames that commented on the topic

  (async () => { //Creates a new function and Starts the function
    while (true) { //While the if condition returns true
      var match, matches, newDocument; //Creates new blank global variables

      for (match in UserNames) //For all unique user names on the MAL topic page
      { //Starts the for condition
        const html = await (await fetch('https://myanimelist.net/profile/' + UserNames[match])).text(); //Gets the fetch response
        newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
        var AffinityPercentage = newDocument.querySelector("div.bar-outer.anime").innerText.replace('0%', '').trim().replace('--', '-').trim(); //Gets the affinity %

        Affinities.push(AffinityPercentage); //Store all the affinities percentages that the script got

      } //Finishes the for condition
      if (newDocument.body.innerText.search('joined') > -1) { //If the text joined was found on the fetched profile page document
        for (match in UserName) //For all User Names on the MAL page
        { //Starts the for condition
          for (matches in UserNames) //For all non duplicated User Names on the MAL page
          { //Starts the for condition
            if (UserNames[matches] === UserName[match].innerText) { //If the User Name matches the user name in the array
              AllComments[match].insertAdjacentHTML("beforeend", '<br>' + 'Affinity to You ' + Affinities[matches]); //Get the matching affinity % to this user and show it
            } //Finishes the if condition
          } //Finishes the for condition
        } //Finishes the for condition

        return; //Return true
      } //Finishes the if condition
    } //Finishes the while condition
  })(); //Finishes the async GetAffinities function
})();