-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathBIT-Programming-Copy testcases.user.js
41 lines (36 loc) · 1.26 KB
/
BIT-Programming-Copy testcases.user.js
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
// ==UserScript==
// @name BIT-Programming-Copy testcases
// @namespace http://tampermonkey.net/
// @version 0.2.1
// @description 简化测试输入、输出的复制操作
// @license GPL-3.0-or-later
// @supportURL https://github.com/YDX-2147483647/BIT-enhanced/issues
// @author Y.D.X.
// @match https://lexue.bit.edu.cn/mod/programming/view.php?*
// @match https://lexue.bit.edu.cn/mod/programming/result.php?*
// @grant none
// ==/UserScript==
(function () {
'use strict'
document.querySelectorAll("a[href*='download=0']").forEach(
function (a) {
const copy_button = document.createElement('pre')
copy_button.textContent = '(copy)'
// Style
copy_button.style.fontSize = '9pt'
copy_button.style.margin = '0.5em'
copy_button.style.display = 'inline'
copy_button.style.color = 'darkgray'
a.parentNode.insertBefore(copy_button, a.parentNode.lastChild)
// TODO: 这还是会引起不必要的GET
fetch(a.href).then(
res => res.text()
).then(plaintext => {
copy_button.addEventListener('copy', function (event) {
event.clipboardData.setData('text/plain', plaintext)
event.preventDefault()
})
})
}
)
})()