Quotes - MAL

Brings back the original MAL quotes button! Now you can copy in a single click original BBCodes and image URLs!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         Quotes - MAL
// @namespace    Quote
// @version      4
// @description  Brings back the original MAL quotes button! Now you can copy in a single click original BBCodes and image URLs!
// @author       hacker09
// @match        https://myanimelist.net/forum/?topicid=*
// @icon         https://t3.gstatic.com/faviconV2?client=SOCIAL&type=FAVICON&fallback_opts=TYPE,SIZE,URL&url=http://myanimelist.net&size=64
// @run-at       document-end
// @grant        none
// ==/UserScript==

(function() {
  'use strict';

  function Function() { //Starts the Function
    setTimeout(() => { //Starts the setTimeout function
      document.querySelectorAll(".mal-post-toolbar > div, .toolbar.left").forEach(function(el, i) { //ForEach topic
        var counter = i; //Create a new variable
        document.querySelector(".mal-post-toolbar > div") === null ? counter = i + 1 : counter = i; //If the page is on the conversation view
        if ((document.querySelectorAll(".username, .item.name")[counter].innerText !== window.dataLayer[0].user_name) && document.querySelectorAll(".mal-post-toolbar > div, .toolbar.left")[i].innerHTML.match("Quote") === null) { //If it is not the script user message and the current message does not have the quote button
          el.insertAdjacentHTML('afterbegin', `<button title="Quote ${document.querySelectorAll(".username, .item.name")[counter].innerText}" class="mal-btn secondary small outline noborder js-topic-message-report"><i class="fa-solid fa-reply fa-fw mr4"></i>Quote</button>`); //Add the quote button on the page

          el.querySelector(`button`).onclick = async function() //When the quote btn is clicked
          { //Starts the onclick function
            document.querySelector(".topic-reply-container.hide") !== null ? document.querySelector(".topic-reply-container.hide").remove() : ''; //Remove needless hidden new reply btn
            document.querySelectorAll(".js-reply-start:not(.pressed)").forEach(el => el.click());; //If the reply btn closed, open it
            document.querySelectorAll(".postnum > a, .item.name")[document.querySelectorAll(".postnum > a, .item.name").length - 1].scrollIntoView(); //Scroll the page to the bottom

            const response = await (await fetch('https://myanimelist.net/includes/quotetext.php', {
              "headers": {
                "content-type": "application/x-www-form-urlencoded"
              },
              "body": `msgid=${document.querySelector(".postnum") !== null ? document.querySelectorAll(".postnum > a")[i].href.match(/\d+/g)[1] : document.querySelectorAll("[class='message']")[i].dataset.id}&csrf token=${document.head.querySelector("[name='csrf_token']").content}`,
              "method": "POST"
            })).text(); //Finishes the fetch

            setTimeout(() => { //Paste the quoted content on the bottom new reply btn
              document.querySelectorAll(".sourceMode > textarea, .forum-post-reply-comment, .bbcode-message-editor").forEach(el => el.value += `[quote=${document.querySelectorAll(".username, .item.name")[counter].innerText} message=${document.querySelector(".postnum") !== null ? document.querySelectorAll(".postnum > a")[i].href.match(/\d+/g)[1] : document.querySelectorAll("[class='message']")[i].dataset.id}]` + new DOMParser().parseFromString(response, "text/html").documentElement.textContent + '[/quote]'); //Paste the text and BBCode content from the topic reply the user wants to quote
            }, 500); //Finishes the click event listener and setTimeout function
          }; //Finishes the onclick function
        } //Finishes the if condition
      }) //Finishes the forEach loop
    }, 500); //Finishes the setTimeout function
  } //FInishes the Function

  Function(); //Run the script when the page is loaded

  document.querySelectorAll(".js-thread-childs").forEach(function(el) { //ForEach reply child
    el.onclick = function() { //When the reply child btn is clicked
      Function(); //Run the script again
    }; //Finishes the onclick function
  }) //Finishes the forEach loop
})();