Advertisement
ShaggyZE1

Mentioner - MAL

Jan 31st, 2023 (edited)
608
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Mentioner - MAL
  3. // @namespace    MALMentioner
  4. // @version      14
  5. // @description  Adds a button to copy the @user name on all users who have commented on any topics 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. // @match        https://myanimelist.net/clubs.php?cid=*
  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        none
  12. // ==/UserScript==
  13. var MouseOverExecuted = 0; //Create a new variable with the value 0
  14. var Executed = 0; //Create a new variable with the value 0
  15. (function() {
  16.     'use strict';
  17.     var MALUserParsedList = []; //Creates a array to later add all non-dup mal usernames on the page
  18.     const ScriptUsername = document.querySelector("a.header-profile-link").innerText; //Gets the script username
  19.  
  20.     document.querySelectorAll('.username > a,div[style*="margin-bottom: 6px;"] > a').forEach(function(UserName) { //Execute this function for each username on the topic/club page
  21.         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
  22.             MALUserParsedList.push(UserName.innerText); //Add the username on the array
  23.  
  24.             window.jQuery('.username > a:contains("' + UserName.innerText + '")').parent().append('<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
  25.             window.jQuery('div[style*="margin-bottom: 6px;"] > a:contains("' + UserName.innerText + '")').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 comments
  26.  
  27.         } //Finishes the if condition
  28.  
  29.         MALUserParsedList = MALUserParsedList.filter(v => v !== ScriptUsername); //Remove the script user username of the array if the script user also commented on the topic
  30.         MALUserParsedList = MALUserParsedList.filter(v => v !== 'removed-user'); //Remove the 'removed-user' username of the array (if existent on the topic page)
  31.  
  32.     }); //Finishes the async function
  33.  
  34.     document.onmouseover = function(e) { //When everything is mouse overed
  35.         if (e.target.className == "topic-reply-box" || e.target.className == "mal-btn primary js-topic-reply-start pressed" || e.target.className == "textarea") { //When the new reply button is pressed/mouse overed or club textarea is mouse overed
  36.             MouseOverExecuted += 1; //Sum the total amount of times that the new reply was pressed/mouse overed or club textarea was mouse overed
  37.             if (MouseOverExecuted === 1) //If it's the first time that the new reply was pressed/mouse overed or club textarea was mouse overed
  38.             { //Starts the if condition
  39.                 if (e.target.className == "topic-reply-box" || e.target.className == "mal-btn primary js-topic-reply-start pressed") //When on a topic page
  40.                 { //Starts the if condition
  41.                     [...document.querySelectorAll(".js-topic-top")].pop().scrollIntoView() // Scroll to bottom of topic "Back to top" button
  42.                     document.querySelector(".js-topic-reply-start").remove(); //Remove top new reply button
  43.                     document.querySelector(".topic-reply-box").remove(); //Remove top reply box
  44.                     if (!document.querySelector(".js-topic-reply-start").classList.contains("pressed")) // If bottom new reply button has not been clicked
  45.                     { //Starts the if condition
  46.                         document.querySelector(".js-topic-reply-start").click() // Click bottom new reply button
  47.                     } //Finishes the if condition
  48.                 } //Finishes the if condition
  49.  
  50.                 document.querySelector(".topic-reply-box,.form-club-user-comment").insertAdjacentHTML("afterend", `<br><textarea id="autocomplete-input" placeholder="Find User" style="resize: none; margin-left: 270px; margin-top: -27px;" cols="10" rows="1"></textarea> <div id="autocomplete-list" style="margin-left: 270px; margin-top: -5px; cursor: pointer; width: 150px; 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
  51.             } //Finishes the if condition
  52.  
  53.             const UserNameList = document.querySelector("#autocomplete-list"); //Add the script div to a variable
  54.  
  55.             document.querySelector("#autocomplete-input").onclick = function() //When the script txt box is clicked
  56.             { //Starts the onclick condition
  57.                 Executed += 1; //Sum the total amount of times that the script txt box was clicked
  58.                 if (Executed === 1) //If it's the first time that the script txt box is clicked
  59.                 { //Starts the if condition
  60.                     UserNameList.style.display = ''; //Display the list containing the User Names
  61.                     MALUserParsedList.forEach(UserName => UserNameList.innerHTML += `<div  title="Click to paste @${UserName} on the text box" onmouseout='this.style.color = "black"' onmouseover='this.style.color = "#6386d5"' onclick='document.querySelector("textarea").value === "" ? document.querySelector("textarea").value += "@${UserName}\\n\\n" : document.querySelector("textarea").value += "@${UserName} "'>\n@${UserName}</div>`); //Add the @UserNames to the script div
  62.                 } //Finishes the if condition
  63.             }; //Finishes the onclick condition
  64.  
  65.             document.querySelector("#autocomplete-input").oninput = function(e) { //When any letter is written on the script txt box
  66.                 const matcher = new RegExp(`^${this.value}`, 'gi'); //Get the letters written on the script txt box and create a regex with that user input
  67.                 const matches = MALUserParsedList.filter(MALUserParsedList => MALUserParsedList.match(matcher)); //Find the user input in the arrays
  68.                 UserNameList.innerHTML = ''; //Remove the previously displayed UserNames
  69.                 matches.forEach(UserName => UserNameList.innerHTML += `<div  title="Click to paste @${UserName} on the text box" onmouseout='this.style.color = "black"' onmouseover='this.style.color = "#6386d5"' onclick='document.querySelector("textarea").value === "" ? document.querySelector("textarea").value += "@${UserName}\\n\\n" : document.querySelector("textarea").value += "@${UserName} "'>\n@${UserName}</div>`); //Display the users found
  70.             }; //Finishes the oninput event listener
  71.         } //Finishes the if condition
  72.     }; //Finishes the onmouseover event listener
  73. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement