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-04-10 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Mentioner - MAL
// @namespace    MALMentioner
// @version      0.1
// @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.
// @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 = []; //Creates a array to later add all non-dup mal usernames on the page
  var ScriptUsername = document.querySelector("a.header-profile-link").innerText; //Gets the script username

  document.querySelectorAll('td.forum_boardrow2 > div > div > a > strong').forEach(function(UserName) { //Execute this function for each username on the topic page
    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
      MALUserParsedList.push(UserName.innerText); //Add the username on the array

      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

    } //Finishes the if condition

    MALUserParsedList = MALUserParsedList.filter(v => v !== ScriptUsername); //Remove the script user username of the array if the script user also commented on the topic
    MALUserParsedList = MALUserParsedList.filter(v => v !== 'removed-user'); //Remove the 'removed-user' username of the array (if existent on the topic page)

  }); //Finishes the async function

  document.querySelector("#quickReply").insertAdjacentHTML("beforeend", '<textarea id="autocomplete-input" placeholder="Find User" style="resize: none; margin-left: 430px; margin-top: -155px;" cols="10" rows="1"></textarea> <div id="autocomplete-list" title="Click to paste @UserName on the text box" style="margin-left: 430px; 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

  var Executed = 0; //Create a new variable with the value 0
  var MALTxtBox = document.querySelector("#messageText"); //Add the Mal txt box to a variable
  var TxtBox = document.querySelector("#autocomplete-input"); //Add the script txt box to a variable
  var UserNameList = document.querySelector("#autocomplete-list"); //Add the script div to a variable

  new MutationObserver(function() { //If the user changes the MAL txt box size
    document.querySelector("#autocomplete-input").style.marginLeft = parseInt(MALTxtBox.style.width) + 10 + 'px'; //Keep the script txt box on the same position
    document.querySelector("#autocomplete-input").style.marginTop = '-' + String(parseInt(MALTxtBox.style.height) + 20 + 'px'); //Keep the script txt box on the same position

    document.querySelector("#autocomplete-list").style.marginLeft = parseInt(MALTxtBox.style.width) + 10 + 'px'; //Keep the script div on the same position
    document.querySelector("#autocomplete-list").style.marginTop = '-' + MALTxtBox.style.height; //Keep the script div on the same position
  }).observe(MALTxtBox, { //Defines the element and attributes to be observed
    attributes: true
  }); //Finishes the definitions that will be observed

  TxtBox.onclick = function() //When the script txt box is clicked
  { //Starts the onclick condition
    Executed += 1; //Sum the total amount of times that the script txt box was clicked
    if (Executed === 1) //If it's the first time that the script txt box is clicked
    { //Starts the if condition
      UserNameList.style.display = 'inline-block'; //Display the list containing the User Names
      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
    } //Finishes the if condition
  }; //Finishes the onclick condition

  TxtBox.oninput = function(e) { //When any letter is written on the script txt box
    var matcher = new RegExp(`^${this.value}`, 'gi'); //Get the letters written on the script txt box and create a regex with that user input
    var matches = MALUserParsedList.filter(MALUserParsedList => MALUserParsedList.match(matcher)); //Find the user input in the arrays
    UserNameList.innerHTML = ''; //Remove the previously displayed UserNames
    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
  }; //Finishes the oninput event listener
})();