Affinity to You

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

Verze ze dne 31. 03. 2021. Zobrazit nejnovější verzi.

// ==UserScript==
// @name         Affinity to You
// @namespace    AffinityShow
// @version      0.5
// @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 MALUserParsedList = new Map(); //Creates a new map to later add all non-dup mal usernames on the page
  var ScriptUsername = document.querySelector("a.header-profile-link").innerText; //Gets the script username

  MALUserParsedList.set(ScriptUsername, {}); //Add the script username to the map,so that the script won't fetch the script user profile
  MALUserParsedList.set('removed-user', {}); //Add the 'removed-user' username to the map,so that the script won't fetch the non existent user profile
  document.querySelectorAll('td.forum_boardrow2 > div > div > a > strong').forEach(async function(UserName) { //Execute this function for each username on the topic page
    if (!MALUserParsedList.has(UserName.innerText)) { //If the username isn't already on the map
      MALUserParsedList.set(UserName.innerText, {}); //Add the username on the map

      const html = await (await fetch('https://myanimelist.net/profile/' + UserName.innerText)).text(); //Gets the fetch response
      var newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
      var AffinityPercentage = newDocument.querySelector("span[class*='bar-inner']").innerText.replace('--', '-').trim(); //Gets the affinity %

      if (AffinityPercentage.match('-') !== null) //If the - symbol exists
      { //Starts the if condition
        AffinityPercentage = '<strong style="color:red; font-weight: normal;">Affinity to You ' + AffinityPercentage + '</strong>'; //Make the text red
      } //Finishes the if condition
      else //If the - symbol DOESN'T exist
      { //Starts the else condition
        AffinityPercentage = '<strong style="color:blue; font-weight: normal;">Affinity to You ' + AffinityPercentage + '</strong>'; //Make the text blue
      } //Finishes the else condition

      window.jQuery('td.forum_boardrow2 > div > div > a > strong:contains("' + UserName.innerText + '")').parent().parent().parent().after(AffinityPercentage); //Add the affinity % to every topic reply that matches the fetched profile username
    } //Finishes the if condition
  }); //Finishes the async function
})();