-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.tamper.js
136 lines (128 loc) · 3.93 KB
/
index.tamper.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
// ==UserScript==
// @name 武汉大学学生自动评教
// @namespace http://tampermonkey.net/
// @version 0.3
// @description Add a floating button to execute custom JS on ugsqs.whu.edu.cn
// @author Texiwustion
// @match https://ugsqs.whu.edu.cn/*
// @grant none
// @license MIT
// ==/UserScript==
(function () {
'use strict';
createFloatingButton();
})();
function createFloatingButton() {
var props = {
moved: false,
checkCursor: true
};
const button = _createButton();
document.body.appendChild(button);
// Hover to changeCursor
button.addEventListener('mousemove', (event)=>{
//防止移动过程中出事
if (!props.checkCursor) {
return
}
const rect = button.getBoundingClientRect();
const halfWidth = rect.width / 2;
const mouseX = event.clientX - rect.left;
if (mouseX < halfWidth) {
button.style.cursor = 'move';
props.moved = true;
} else {
button.style.cursor = 'default';
props.moved = false;
}
});
// Make the button draggable
button.onmousedown = (event)=>{
// Change position to absolute
button.style.position = 'absolute';
let shiftX = event.clientX - button.getBoundingClientRect().left;
let shiftY = event.clientY - button.getBoundingClientRect().top;
//console.log(shiftX, shiftY);
function moveAt(pageX, pageY) {
button.style.cursor = 'move';
button.style.left = pageX - shiftX + 'px';
button.style.top = pageY - shiftY + 'px';
}
function onMouseMove(event) {
if (props.moved) {
moveAt(event.pageX, event.pageY);
props.checkCursor = false;
}
}
document.addEventListener('mousemove', onMouseMove);
button.onmouseup = function () {
document.removeEventListener('mousemove', onMouseMove);
button.onmouseup = null;
// Change position back to fixed
button.style.position = 'fixed';
//checkCursor
props.checkCursor = true;
};
};
button.ondragstart = () => false;
// Add two div elements for the left and right halves of the button
const leftHalf = _createLelfHalfButton();
const rightHalf = _createRightHalfButton();
rightHalf.addEventListener('click', executeCustomJS);
button.appendChild(leftHalf);
button.appendChild(rightHalf);
}
function executeCustomJS() {
let counter = 0;
document.querySelectorAll('.controls').forEach(control => {
const radios = control.querySelectorAll('input[type="radio"]');
if (counter === 14 && radios[1]) {
radios[1].checked = true;
} else if (radios[0]) {
radios[0].checked = true;
}
counter++;
});
document.querySelectorAll('[data-yjzb="开放型问题"]').forEach(element => {
const textarea = element.querySelector('textarea');
if (textarea) {
textarea.value += '\nnull';
}
});
//提交
document.getElementById("pjsubmit").click();
}
function _createButton() {
const button = document.createElement('button');
button.style.position = 'fixed';
button.style.width = '50px';
button.style.height = '50px';
button.style.right = '20vh';
button.style.top = '20vh';
button.style.zIndex = '100000';
button.style.borderRadius = '50%';
button.style.backgroundColor = '#ffffff';
button.style.border = '3px solid #ccc';
button.style.cursor = 'move';
return button;
}
function _createLelfHalfButton() {
const leftHalf = document.createElement('div');
leftHalf.style.width = '50%';
leftHalf.style.height = '100%';
leftHalf.style.backgroundColor = 'black';
leftHalf.style.position = 'absolute';
leftHalf.style.left = '0';
leftHalf.style.top = '0';
return leftHalf;
}
function _createRightHalfButton() {
const rightHalf = document.createElement('div');
rightHalf.style.width = '50%';
rightHalf.style.height = '100%';
rightHalf.style.backgroundColor = 'white';
rightHalf.style.position = 'absolute';
rightHalf.style.right = '0';
rightHalf.style.top = '0';
return rightHalf;
}