Mentioner - MAL

Adds a button to copy the @user name on all users who have commented on any topic on MAL. The script also adds a search user name box near the box were the reply is written, so that you can search for any user that commented on that topic and click on the displayed @UserName to auto paste the @UserName into the reply box.

当前为 2021-12-22 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Mentioner - MAL
  3. // @namespace MALMentioner
  4. // @version 0.3
  5. // @description Adds a button to copy the @user name on all users who have commented on any topic on MAL. The script also adds a search user name box near the box were the reply is written, so that you can search for any user that commented on that topic and click on the displayed @UserName to auto paste the @UserName into the reply box.
  6. // @author hacker09
  7. // @match https://myanimelist.net/forum/?topicid=*
  8. // @icon https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
  9. // @run-at document-end
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15. var MALUserParsedList = []; //Creates a array to later add all non-dup mal usernames on the page
  16. var ScriptUsername = document.querySelector("a.header-profile-link").innerText; //Gets the script username
  17.  
  18. document.querySelectorAll('td.forum_boardrow2 > div > div > a > strong').forEach(function(UserName) { //Execute this function for each username on the topic page
  19. if (!MALUserParsedList.includes(UserName.innerText) && UserName.innerText !== ScriptUsername && UserName.innerText !== 'removed-user') { //If the username isn't already on the array and if isn't the Script Username or the removed-user
  20. MALUserParsedList.push(UserName.innerText); //Add the username on the array
  21.  
  22. window.jQuery('td.forum_boardrow2 > div > div > a > strong:contains("' + UserName.innerText + '")').parent().after('<a title="Copy @' + UserName.innerText + '" onclick=navigator.clipboard.writeText("@' + UserName.innerText + '") style="cursor: pointer; margin-left: 9px; height: 10px; width: 10px; background-size: cover; display: inline-block; transform: scale(1.5); vertical-align: top; margin-top: 2px; background-image: url(https://i.imgur.com/vU0m0ye.png);"></a>'); //Add the copy @UserName button to every username that replied on the topic
  23.  
  24. } //Finishes the if condition
  25.  
  26. MALUserParsedList = MALUserParsedList.filter(v => v !== ScriptUsername); //Remove the script user username of the array if the script user also commented on the topic
  27. MALUserParsedList = MALUserParsedList.filter(v => v !== 'removed-user'); //Remove the 'removed-user' username of the array (if existent on the topic page)
  28.  
  29. }); //Finishes the async function
  30.  
  31. document.querySelector("#quickReply").insertAdjacentHTML("beforeend", '<textarea id="autocomplete-input" placeholder="Find User" style="resize: none; margin-left: 465px; margin-top: -155px;" cols="10" rows="1"></textarea> <div id="autocomplete-list" title="Click to paste @UserName on the text box" style="margin-left: 465px; margin-top: -130px; cursor: pointer; width: 40%; height: 145px; overflow-y: scroll; display: none;"></div>'); //Add a new div and text area to the page display: none; grid-template-columns: 1fr 1fr 1fr 1fr 1fr; grid-gap: 5px
  32.  
  33. var Executed = 0; //Create a new variable with the value 0
  34. var MALTxtBox = document.querySelector("#messageText"); //Add the Mal txt box to a variable
  35. var TxtBox = document.querySelector("#autocomplete-input"); //Add the script txt box to a variable
  36. var UserNameList = document.querySelector("#autocomplete-list"); //Add the script div to a variable
  37.  
  38. new MutationObserver(function() { //If the user changes the MAL txt box size
  39. document.querySelector("#autocomplete-input").style.marginLeft = parseInt(MALTxtBox.style.width) + 10 + 'px'; //Keep the script txt box on the same position
  40. document.querySelector("#autocomplete-input").style.marginTop = '-' + String(parseInt(MALTxtBox.style.height) + 25 + 'px'); //Keep the script txt box on the same position
  41.  
  42. document.querySelector("#autocomplete-list").style.marginLeft = parseInt(MALTxtBox.style.width) + 10 + 'px'; //Keep the script div on the same position
  43. document.querySelector("#autocomplete-list").style.marginTop = '-' + MALTxtBox.style.height; //Keep the script div on the same position
  44. }).observe(MALTxtBox, { //Defines the element and attributes to be observed
  45. attributes: true
  46. }); //Finishes the definitions that will be observed
  47.  
  48. TxtBox.onclick = function() //When the script txt box is clicked
  49. { //Starts the onclick condition
  50. Executed += 1; //Sum the total amount of times that the script txt box was clicked
  51. if (Executed === 1) //If it's the first time that the script txt box is clicked
  52. { //Starts the if condition
  53. UserNameList.style.display = 'inline-block'; //Display the list containing the User Names
  54. MALUserParsedList.forEach(UserName => UserNameList.innerHTML += "<div onmouseout='this.style.color = \"" + 'black' + "\"' onmouseover='this.style.color = \"" + '#6386d5' + "\"' onclick='document.querySelector(\"" + "#messageText" + "\").value += \"" + '\\n@' + "\" + \"" + UserName + "\"'>\n@" + UserName + "</div>"); //Add the @UserNames to the script div
  55. } //Finishes the if condition
  56. }; //Finishes the onclick condition
  57.  
  58. TxtBox.oninput = function(e) { //When any letter is written on the script txt box
  59. var matcher = new RegExp(`^${this.value}`, 'gi'); //Get the letters written on the script txt box and create a regex with that user input
  60. var matches = MALUserParsedList.filter(MALUserParsedList => MALUserParsedList.match(matcher)); //Find the user input in the arrays
  61. UserNameList.innerHTML = ''; //Remove the previously displayed UserNames
  62. matches.forEach(UserName => UserNameList.innerHTML += "<div onmouseout='this.style.color = \"" + 'black' + "\"' onmouseover='this.style.color = \"" + '#6386d5' + "\"' onclick='document.querySelector(\"" + "#messageText" + "\").value += \"" + '\\n@' + "\" + \"" + UserName + "\"'>\n@" + UserName + "</div>"); //Display the users found
  63. }; //Finishes the oninput event listener
  64. })();