ReverseMarshMallows

マシュマロを逆順にするボタンを追加。また、マシュマロをクリックしたときに別windowが開くようにする。

目前為 2024-08-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         ReverseMarshMallows
// @namespace    https://github.com/aplysia56108/ReverseMarshMallows
// @version      1.0
// @description  マシュマロを逆順にするボタンを追加。また、マシュマロをクリックしたときに別windowが開くようにする。
// @author       aplysia56108
// @license      MIT
// @match        https://marshmallow-qa.com/messages*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js
// ==/UserScript==

(function () {
  "use strict";
  const putLinkBtn = () => {
    const messages = document.getElementById("messages");

    const tmpList = [];
    while (messages.firstChild) {
      const child = messages.firstChild;
      if (child.tagName == "LI") tmpList.push(child);
      messages.removeChild(child);
    }
    for (let i = 0; i < tmpList.length; i++) {
      const child = tmpList[i];
      messages.appendChild(child);
    }

    const linkList = messages.getElementsByClassName("text-zinc-900");

    for (let i = 0; i < tmpList.length; i++) {
      if (messages.children[i].firstChild.id == "linkBtn") continue;

      const LinkBtn = document.createElement("a");
      LinkBtn.id = "linkBtn";
      LinkBtn.innerHTML = "<br>別タブで開く</br>";
      LinkBtn.style.width = "100px";
      LinkBtn.style.height = "30px";
      LinkBtn.style.zIndex = "99824433";
      LinkBtn.href = linkList[i].href;
      LinkBtn.target = "_blank";
      messages.children[i].prepend(LinkBtn);
    }
  };

  putLinkBtn();

  const reverseBtn = document.createElement("button");
  document.querySelector("main").prepend(reverseBtn);
  const BtnMessages = ["正順", "逆順"];
  let isReversed = 0;
  reverseBtn.textContent = BtnMessages[isReversed];
  reverseBtn.type = "button";
  reverseBtn.style.width = "100px";
  reverseBtn.style.height = "30px";
  reverseBtn.style.zIndex = "99824433";
  reverseBtn.style.backgroundColor = "white";

  reverseBtn.addEventListener("click", () => {
    isReversed ^= 1;
    reverseBtn.textContent = BtnMessages[isReversed];

    const messages = document.getElementById("messages");

    const tmpList = [];
    while (messages.firstChild) {
      const child = messages.firstChild;
      if (child.tagName == "LI") tmpList.push(child);
      messages.removeChild(child);
    }

    tmpList.reverse();
    for (let i = 0; i < tmpList.length; i++) {
      const child = tmpList[i];
      messages.appendChild(child);
    }

    putLinkBtn();
  });
})();