MantisBT Helper

Copy the text of a link to the clipboard when a button next to it is clicked

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         MantisBT Helper
// @namespace    https://greasyfork.org/zh-CN/users/1198037-gavin0x0
// @version      0.3
// @description  Copy the text of a link to the clipboard when a button next to it is clicked
// @license      MIT
// @author       Gavin
// @match        http://dist.ius.plus/flyinsono/*
// @grant        none
// ==/UserScript==
(function () {
    "use strict";
    function create_copy_text_button(text4display,text4copy) {
        const copy_button = document.createElement("p");
        copy_button.innerHTML = text4display;
        copy_button.onclick = function () {
            copy_button.innerHTML = "已复制 ✅";
            setTimeout(function () {
                copy_button.innerHTML = text4display;
            }, 1200);
            const text = text4copy;
            const textarea = document.createElement("textarea");
            textarea.value = text;
            document.body.appendChild(textarea);
            textarea.select();
            document.execCommand("copy");
            document.body.removeChild(textarea);
        };
        return copy_button;
    }
    var next_version_str = "0.0.0";
    var latest_version = "0";
    var links = document.getElementsByTagName("a");
    for (var i = 0; i < links.length; i++) {
        if (!links[i].classList.contains("file")) {
            continue;
        }
        var version = links[i].innerHTML.replace(".zip", "");
        var text_to_copy = "已修复\nversion: " + version;
        let button = create_copy_text_button("修复于此版本 ✏️",text_to_copy);
        var td = document.createElement("td");
        td.style.cursor = "pointer";
        td.appendChild(button);
        var parentTd = links[i].parentNode.parentNode;
        parentTd.parentNode.insertBefore(td, parentTd);
        var last_dot = version.lastIndexOf(".");
        var version_number = parseInt(version.substring(last_dot + 1));
        if (version_number > latest_version) {
            latest_version = version_number;
        }else{
            continue;
        }
        version_number = version_number + 1;
        if (version_number < 10) {
            version_number = "0" + version_number;
        }
        next_version_str = version.substring(0, last_dot + 1) + version_number;
    }
    if (next_version_str == "0.0.0") {
        return;
    }
    var trs = document.getElementsByTagName("tr");
    var th = document.createElement("th");
    th.style.cursor = "pointer";
    trs[0].insertBefore(th, trs[0].firstChild);
    var next_version_to_copy = "已修复\nversion: " + next_version_str;
    let button = create_copy_text_button("下一个版本 ✏️",next_version_to_copy);
    th.appendChild(button);
  })();