Skip to content

Instantly share code, notes, and snippets.

@Gavin0x0
Created March 15, 2023 12:52
Show Gist options
  • Save Gavin0x0/bbe06ea50fc2a0caac5f79fb967e551e to your computer and use it in GitHub Desktop.
Save Gavin0x0/bbe06ea50fc2a0caac5f79fb967e551e to your computer and use it in GitHub Desktop.
MantisBT Helper
// ==UserScript==
// @name MantisBT Helper
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Copy the text of a link to the clipboard when a button next to it is clicked
// @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);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment