Affinity to You

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

安裝腳本?
作者推薦腳本

您可能也會喜歡 Mentioner - MAL

安裝腳本
  1. // ==UserScript==
  2. // @name Affinity to You
  3. // @namespace AffinityShow
  4. // @version 22
  5. // @description Shows the "Affinity to You" % that all users who have commented on any topic on MAL have with you!
  6. // @author hacker09
  7. // @match https://myanimelist.net/*/*/*/stats*
  8. // @match https://myanimelist.net/forum/?topicid=*
  9. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
  10. // @run-at document-end
  11. // @grant GM_getValue
  12. // @grant GM_setValue
  13. // @grant GM_listValues
  14. // @grant GM_deleteValue
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19. var TimesExecuted = 0; //Create a new global variable
  20. var UserAffinityList = []; //Create a new global array
  21. var MALUserParsedList = new Map(); //Creates a new map to later add all non-dup mal usernames on the page
  22.  
  23. const AffinityList = document.createElement("button"); //Creates a btn element
  24. AffinityList.setAttribute("style", "display: none; background-color: snow; margin-left: 10px;"); //The CSS for the "button"
  25. AffinityList.setAttribute("class", "inputButton"); //Adds a class to the button
  26.  
  27. const ShowAffinityList = document.createElement("input"); //Creates an a element
  28. ShowAffinityList.setAttribute("style", "background-color: #4165ba;"); //The CSS for the input btn
  29. ShowAffinityList.setAttribute("class", "inputButton"); //Adds a class to the input btn
  30. ShowAffinityList.setAttribute("value", " Show Affinity list"); //Adds the input btn default text
  31. ShowAffinityList.setAttribute("readonly", "readonly"); //Make the input btn default text not editable
  32.  
  33. if (document.querySelector("#post1, .js-topic-top") === null) //If the user is using the conversation view or if the topic has nearly no replies while using the conversation view
  34. { //Starts the if condition
  35. document.querySelector(".left > span.caption, #members").before(ShowAffinityList, AffinityList); //Append the button and the input btn text next to the reply btn
  36. } //Finishes the if condition
  37. else //if the user is not using the conversation view or if the topic has nearly no replies while using the classic view
  38. { //Starts the else condition
  39. document.querySelector(".topic-reply-container.hide") === null ? document.querySelector(".js-topic-top").before(ShowAffinityList, AffinityList) : document.querySelector(".topic-reply-container:not(.hide) > div > div > .js-reply-start").after(ShowAffinityList, AffinityList); //Append the button and the input btn text next to the reply btn
  40. } //Finishes the else condition
  41.  
  42. ShowAffinityList.onclick = function() { //When the Show Affinity button is clicked
  43. if (AffinityList.style.display === 'none') { //If the Affinity list is hidden
  44. AffinityList.style.display = ''; //Show the Affinity List
  45. ShowAffinityList.value = " Hide Affinity list"; //Change the Show Affinity List text to Hide Affinity List
  46. } else { //If the Affinity list is being shown
  47. AffinityList.style.display = 'none'; //Hide the Affinity List
  48. ShowAffinityList.value = " Show Affinity list"; //Change the Hide Affinity List text to Show Affinity List
  49. } //Finishes the else condition
  50. }; //Finishes the onclick event listener
  51.  
  52. if (GM_getValue('Date') === undefined) //If the date wasn't yet stored on tampermonkey
  53. { //Starts the if condition
  54. GM_setValue('Date', new Date().getMonth()); //Get and save the actual month as a number
  55. } //Finishes the if condition
  56.  
  57. if (new Date().getMonth() !== GM_getValue('Date')) //If the month number stored on tampermonkey is a previous month
  58. { //Starts the if condition
  59. GM_listValues().forEach(function(a) { //ForEach data stored on tampermonkey
  60. if (a !== GM_getValue('Date')) //If the current looped element isn't the past month number stored on tampermonkey
  61. { //Starts the if condition
  62. GM_deleteValue(a); //Delete the actual looped value of the TamperMonkey storage
  63. } //Finishes the if condition
  64. }); //Finishes the foreach condition to erase all the users stored on tampermonkey
  65. } //Finishes the if condition
  66.  
  67. window.onscroll = function() { //Starts the onscroll event listener
  68. TimesExecuted += 1; //Sum the total amount of times that the page was scrolled
  69. if (TimesExecuted === 1) //If it's the first time that the page was scrolled
  70. { //Starts the if condition
  71. MALUserParsedList.set(document.querySelector("a.header-profile-link").innerText, {}); //Add the script username to the map,so that the script won't fetch the script user profile
  72. MALUserParsedList.set('removed-user', {}); //Add the 'removed-user' username to the map, so that the script won't fetch the nonexistent user profile
  73. document.querySelectorAll('.username, .item.name, .word-break').forEach(async function(UserName) { //Execute this function for each username on the topic page
  74.  
  75. if (!MALUserParsedList.has(UserName.innerText) && GM_getValue(UserName.innerText) !== undefined) { //If the username isn't already on the map and is stored on tampermonkey
  76. MALUserParsedList.set(UserName.innerText, {}); //Add the username on the map
  77.  
  78. if (GM_getValue(UserName.innerText).match(/-\d+(?:\.\d+)?(?=%)/) === null && GM_getValue(UserName.innerText).match('Unknown') === null) //If the - symbol doesn't exist and if the affinity isn't Unknown on the tampermonkey stored data for this user
  79. { //Starts the if condition
  80. UserAffinityList.push('<a href="https://myanimelist.net/profile/' + UserName.innerText + '" target="_blank" style="cursor: pointer;" title="Click to open the ' + UserName.innerText + '\'s Profile">' + UserName.innerText + ' ' + GM_getValue(UserName.innerText).match(/\d+(?:\.\d+)?(?=%)/)[0] + '%</a>'); //Store all the topic User Names and links
  81. } //Finishes the if condition
  82.  
  83. [...document.querySelectorAll('.username, .item.name, .word-break')].filter(a => a.textContent.includes(UserName.innerText)).forEach(a => a.parentNode.insertAdjacentHTML("beforeend", '<br>' + GM_getValue(UserName.innerText))); //Add the affinity % to every topic reply that matches the fetched profile username
  84. } //Finishes the if condition
  85.  
  86. if (!MALUserParsedList.has(UserName.innerText) && GM_getValue(UserName.innerText) === undefined) { //If the username isn't already on the map and isn't stored on tampermonkey
  87. MALUserParsedList.set(UserName.innerText, {}); //Add the username on the map
  88.  
  89. const html = await (await fetch('https://myanimelist.net/profile/' + UserName.innerText)).text(); //Gets the fetch response
  90. var newDocument = new DOMParser().parseFromString(html, 'text/html'); //Parses the fetch response
  91. var AffinityPercentage = newDocument.querySelector("span[class*='bar-inner']") !== null ? newDocument.querySelector("span[class*='bar-inner']").innerText.replace('--', '-').trim() : ' Unknown'; //Make the variable global
  92.  
  93. if (AffinityPercentage.match('-') === null && AffinityPercentage.match('Unknown') === null) //If the - symbol doesn't exist and if the affinity isn't Unknown
  94. { //Starts the if condition
  95. UserAffinityList.push('<a href="https://myanimelist.net/profile/' + UserName.innerText + '" target="_blank" style="cursor: pointer;" title="Click to open the ' + UserName.innerText + '\'s Profile">' + UserName.innerText + ' ' + AffinityPercentage + '</a>'); //Store all the topic User Names and links
  96. } //Finishes the if condition
  97.  
  98. AffinityPercentage = '<a href="https://myanimelist.net/sharedanime.php?u1=' + UserName.innerText + '&u2=' + document.querySelector("a.header-profile-link").innerText + '" target="_blank" style="cursor: pointer;" title="Click to open the Shared Anime page between you and ' + UserName.innerText + '"><strong style="color:' + (AffinityPercentage.match('-') === null && AffinityPercentage.match('Unknown') === null ? "blue" : "red") + '; font-weight: normal;">Affinity to You ' + AffinityPercentage + '</strong></a>'; //Make the text blue/red
  99.  
  100. GM_setValue(UserName.innerText, AffinityPercentage); //Get and save the UserName and the AffinityPercentage on tampermonkey
  101. [...document.querySelectorAll('.username, .item.name, .word-break')].filter(a => a.textContent.includes(UserName.innerText)).forEach(a => a.parentNode.insertAdjacentHTML("beforeend", AffinityPercentage)); //Add the affinity % to every topic reply that matches the fetched profile username
  102. } //Finishes the if condition
  103.  
  104. if (UserAffinityList.length != 0) //If there are any users that have a positive affinity with you in the page
  105. { //Starts the if condition
  106. AffinityList.innerHTML = UserAffinityList.sort(function(a, b) { //Add the sorted list to the button element
  107. var aA = parseFloat(a.match(/\d+(?:\.\d+)?(?=%)/)); //Get only the Affinity % number
  108. var bA = parseFloat(b.match(/\d+(?:\.\d+)?(?=%)/)); //Get only the Affinity % number
  109. return bA > aA ? 1 : -1; //Compare the Affinity % and sort the array
  110. }).join('<br><br>'); //Finishes the sorting condition and add "spaces" between the links
  111. } //Finishes the if condition
  112. else //If there are NO users that have a positive affinity with you in the page
  113. { //Starts the else condition
  114. AffinityList.innerHTML = '<strong style="color:red; font-weight: normal;">No one here has a positive affinity with you</strong>'; //Add a text
  115. } //Finishes the else condition
  116.  
  117. }); //Finishes the async function
  118. } //Finishes the if condition
  119. }; //Finishes the onscroll event listener
  120. })();

QingJ © 2025

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