项目场景:
提示:这里简述项目相关背景:
例如:项目场景:油猴插件swagger复制对应的接口 post ts的时候复制对应的数据以及类型
代码
// ==UserScript==
// @name 接口
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author You
// @match http://*/*/swagger-ui.html*
// @icon data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant none
// ==/UserScript==
(function () {
"use strict";
const divBottom = () => {
let div = document.createElement("div");
let button1 = document.createElement("button");
let button2 = document.createElement("button");
button1.type = "text";
button1.onclick = () => {
$(".endpoints").attr("style", "display: none;");
//.attr("class", "resource");
};
button2.onclick = () => {
$(".endpoints").attr("style", "display: block;");
};
button1.innerHTML = "全部收起";
button2.innerHTML = "全部展开";
div.appendChild(button1);
div.appendChild(button2);
$("#message-bar").append(div);
$("#message-bar").append(
'<textarea id="copy" style="display:none;"></textarea>'
);
$("#message-bar").append(
'<div id="obj" style="font-size:14px; height: 131px;width: 352px;overflow: auto;background-color: red;position: fixed;top: 56px;right: 10px;"></div>'
);
};
const list = () => {
let button = document.createElement("button");
let button1 = document.createElement("button");
button.innerHTML = "复制url";
button1.innerHTML = "ts类型复制";
button.type = "text";
button.className = "ppp";
button1.className = "pppp";
$("h3").parent().append(button);
$("h3").parent().append(button1);
$(".pppp").on("click", (e) => {
let obj = {};
$.each(
$(e.target).parent().next().find(".propName"),
(index, element) => {
let aa = element.nextSibling.nextSibling;
let cc = aa.nextSibling.nextSibling.nextSibling.nextSibling;
let objarr = {
integer: "number",
string: "string",
boolean: "boolean",
};
if (cc) {
obj[element.innerHTML] =
objarr[aa.innerHTML] +
",//" +
cc.childNodes[0].innerHTML +
"<br/>";
} else {
obj[element.innerHTML] = objarr[aa.innerHTML] + ",<br/>";
}
}
);
// .replaceAll('"', "")","
$("#obj").html(
JSON.stringify(obj).replaceAll('","', "").replaceAll('"', "")
);
console.log(obj, $("#obj").html());
$("#copy").text(JSON.stringify(obj).replaceAll('"', "")).show();
var ele = document.getElementById("copy");
ele.select();
document.execCommand("copy", false, null);
$("#copy").hide();
});
$(".ppp").on("click", (e) => {
$("#copy")
.text($(e.target).parent().find(".path").find("a").html())
.show();
var ele = document.getElementById("copy");
ele.select();
document.execCommand("copy", false, null);
$("#copy").hide();
});
};
$("#select_baseUrl").on("change", function () {
setTimeout(() => {
divBottom();
list();
}, 1000);
});
// Your code here...
})();