油猴脚本-swagger-copy-url

本脚本用于swagger文档网站快速复制URL。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// ==UserScript==
// @name swagger 快捷复制
// @namespace http://tampermonkey.net/
// @version 2026-03-11
// @description swagger ui 页面上URL行后边增加复制按钮
// @author You
// @match http://172.16.101.244:9033/prod-api/swagger-ui.html
// @icon https://www.google.com/s2/favicons?sz=64&domain=101.244
// @grant none
// ==/UserScript==

(function() {
'use strict';
// Your code here...
window.addEventListener('load', () => {
setTimeout(() => {
const input = document.createElement('input');
[...document.querySelectorAll('.opblock-tag')].forEach(dom => {
dom.addEventListener('click', (e) => {
setTimeout(() => {
const sub = dom.nextElementSibling;
if (sub.tagName == 'NOSCRIPT') return;
const urlDomList = sub.querySelectorAll('.opblock-summary')
urlDomList.forEach(urlDom => {
const path = urlDom.querySelector('.opblock-summary-path').innerText;
const icon = document.createElement('span');
icon.innerText = 'copy'
icon.style.padding = '0 4px';
icon.addEventListener('click', (e) => {
e.stopPropagation();
document.body.appendChild(input);
input.value = path;
input.select();
document.execCommand('copy');
document.body.removeChild(input);
});
urlDom.appendChild(icon);
})
}, 0)
})
})
}, 1000)
})
})();