-
Notifications
You must be signed in to change notification settings - Fork 1
/
aoguai-智慧树(知到)习惯分平时分问答垃圾话生成器.user.js
311 lines (289 loc) · 10.2 KB
/
aoguai-智慧树(知到)习惯分平时分问答垃圾话生成器.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
// ==UserScript==
// @name aoguai-智慧树(知到)习惯分平时分问答半自动复读垃圾话生成器
// @namespace http://tampermonkey.net/
// @version 1.1.9.1
// @description 智慧树(知到)习惯分平时分问答半自动复读垃圾话生成器
// @author aoguai
// @copyright 2023, aoguai (https://github.com/aoguai)
// @require https://unpkg.com/axios/dist/axios.min.js
// @match https://qah5.zhihuishu.com/qa.html
// @grant GM_xmlhttpRequest
// @connect *
// @license MIT
// ==/UserScript==
/**
* 主要配置参数
*/
const publish_p = 0; // 进入问答后是否自动点击发表。可改为1或0。1为自动点击发表,0为手动点击发表。默认为0
const nonsense_p = 0; // 进入问答后自动输入时,是否需要中立与否定回答。可改为0、1、2、3。0为都不需要,1为需要中立回答,2为需要否定回答,3为都需要,默认为0
const close_p = 0; // 进入问答发表后是否自动关闭问答。(需要配合publish_p实现,仅publish_p开启时有效)可改为1或0。1为是,0为否。默认为0
(function() {
/**
* 初始化事件
*/
const e = new MouseEvent("click", {
bubbles: true,
cancelable: true,
});
const input = new Event("input");
const CASLOGC = document.cookie.split(';')
.filter(item => item.includes('CASLOGC'))
.toString().trim()
.replace(/\"/g, "'").split('=')[1]
const uuid = JSON.parse(decodeURIComponent(CASLOGC)).uuid
let params = {
uuid: uuid, dateFormate: new Date() * 1,
pageIndex: 0, pageSize: 50
}
params.recruitId = document.URL.split('?')[1].split('&')
.filter( item => item.includes('recruitId'))[0].split('=')[1]
params.courseId = document.URL.split('/')[6].split('?')[0]
/**
* 转换肯定句为否定句的函数
* @param {string} sentence 原始句子
* @returns {string} 转换后的句子
*/
function convertPositiveToNegative(sentence) {
const patterns = [
{ regex: /是/g, replacement: '不是' },
{ regex: /有/g, replacement: '没有' },
// 添加更多的替换规则...
];
let result = sentence;
patterns.forEach(pattern => {
result = result.replace(pattern.regex, pattern.replacement);
});
return result;
}
/**
* 垃圾话生成函数
* @param {string} mode 生成模式
* @returns {string} 垃圾话
*/
function generateTrashTalk(mode) {
const answerContentElement = document.querySelector('.answer-content');
const questionElement = answerContentElement ? answerContentElement.children[0] : null;
let question = '';
let ans = '';
if (questionElement) {
question = questionElement.innerText;
ans = question;
} else {
const alternativeQuestionElement = document.querySelector('.question-content > p > span');
if (alternativeQuestionElement) {
question = alternativeQuestionElement.innerText;
ans = question
.replace(/\?|。|!|!|?|\.|{是|对}{吗|嘛|么}|什么|/g, '')
.replace(/嘛|吗|么/g, '')
.replace(/是{否|不是}/g, '是')
.replace(/你们|你/g, '我')
.replace(/有没有/, '有')
.replace(/能不能/, '能')
.replace(/[\(|(][\u4E00-\u9FA5A-Za-z0-9_]+[\)|)]/g, '');
}
}
const answer = {
positive: [ans],
negative: [convertPositiveToNegative(ans)],
nonsense: [
'我们需要辩证看待,有些是好的,有些是不好的',
'这不是绝对的,我们要理性看待',
'没有绝对是好的,还是坏的'
]
};
let answerArray = Object.values(answer);
if (mode === '') {
if (nonsense_p === 0) {
answerArray = answer.positive;
} else if (nonsense_p === 1) {
answerArray = answer.nonsense.concat(answer.positive);
} else if (nonsense_p === 2) {
answerArray = answer.negative.concat(answer.positive);
} else if (nonsense_p === 3) {
answerArray = answer.nonsense.concat(answer.positive, answer.negative);
}
} else if (Object.keys(answer).includes(mode)) {
answerArray = answer[mode];
}
const randomIndex = parseInt(Math.random() * 100) % answerArray.length;
return answerArray[randomIndex];
}
/**
* 渲染按钮样式
* @returns {string} 按钮样式的 HTML
*/
function Render() {
return `
<div class="wheel-panel">
<button class="wheel-button wheel-positive">肯定</button>
<button class="wheel-button wheel-negative">否定</button>
<button class="wheel-button wheel-nonsense">中立</button>
</div>
<style>
.wheel-panel {
position: fixed;
right: 30em;
top: 12em;
width: 8em;
height: 3em;
z-index: 3000;
}
.wheel-button {
cursor:pointer;
margin: .5em 0;
padding: 0 .5em;
height: 3em;
width: 8em;
border: 0;
outline: 0;
border-radius: .5em;
color: #f0f8ff;
font-size: 1.5em;
letter-spacing: .1em;
}
.wheel-positive {
background: #7fd826;
}
.wheel-negative {
background: #d82626;
}
.wheel-positive:hover {
background: #99e051;
}
.wheel-negative:hover {
background: #e05151;
}
.wheel-nonsense {
background: black;
}
.wheel-nonsense:hover {
background: #333333;
}
</style>
`;
}
/**
* 绑定按钮事件
*/
function binding() {
const panel = document.querySelector('.wheel-panel');
if (!panel) {
console.log('panel not found');
return;
}
panel.addEventListener('click', (e) => {
const text = document.querySelector('.comment-input.el-textarea > textarea');
const mode = e.target.classList[1].split('wheel-')[1];
const trashTalk = generateTrashTalk(mode);
console.log(trashTalk);
console.log(text);
text.value = trashTalk;
text.dispatchEvent(input);
publish();
});
}
/**
* 自动点击发表函数
*/
const publish = () => {
if (publish_p === 0) return;
const btn = document.querySelector("div.up-btn.set-btn");
if (!btn) return;
btn.click();
// 获取所有具有指定类名的 <span> 元素
const spanElements = document.querySelectorAll('.ative-btn > span.ZHIHUISHU_QZMD');
// 判断是否存在第二个匹配的元素,并点击它
if (spanElements.length >= 2) {
const secondSpanElement = spanElements[1];
secondSpanElement.click();
// 添加延时,延时时间为1秒(1000毫秒)
setTimeout(() => {
// 获取第一个具有指定类名的 <i> 元素
const firstIElement = document.querySelector('i.iconfont.icondianzan1');
// 判断是否存在匹配的 <i> 元素,并执行点击操作
if (firstIElement) {
firstIElement.click();
}
}, 1000); // 设置延时为1秒
}
// 2秒后自动关闭当前窗口
const delay = async () => {
await new Promise((resolve) => setTimeout(resolve, 2000));
if (close_p === 1) {
const ua = navigator.userAgent;
if (/MSIE/.test(ua)) {
// close IE
if (/MSIE 6.0/.test(ua)) {
window.opener = null;
window.close();
} else {
window.open("", "_top");
window.top.close();
}
} else {
// close chrome;It is effective when it is only one.
window.opener = null;
window.open("", "_self");
window.close();
}
}
};
delay();
};
/**
* 添加按钮函数
*/
function addWheelPanel() {
const dialog = document.querySelector('.questionDialog.ZHIHUISHU_QZMD');
if (dialog) {
dialog.insertAdjacentHTML('beforeend', Render());
binding();
}
}
/**
* 处理添加按钮可见性变化的回调
*/
function handleIntersection(entries) {
const wheelPanel = document.querySelector('.wheel-panel');
if (entries[0].isIntersecting) {
wheelPanel.style.display = 'block';
} else {
wheelPanel.style.display = 'none';
}
}
/**
* 调整添加按钮可见函数
*/
function observeHeaderTitle() {
const headerTitle = document.querySelector('.el-dialog__wrapper');
const options = {
root: null,
rootMargin: '0px',
threshold: 0
};
const observer = new IntersectionObserver(handleIntersection, options);
observer.observe(headerTitle);
}
window.onload = () => {
async function detail() {
const btn = document.querySelector('.my-answer-btn')
if (btn == null) return
btn.dispatchEvent(e)
setTimeout(() => {
const text = document.querySelector('textarea')
if (!text) return
text.innerText = generateTrashTalk("")
text.dispatchEvent(input)
binding()
}, 200)
setTimeout(function () {
publish()
}, 1000);
}
setTimeout(detail, 1000);
// 在合适的时机调用该函数来添加渲染的按钮样式
addWheelPanel();
// 在合适的时机调用该函数来监听并处理可见性变化
observeHeaderTitle();
}
})();