-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsgyb.js
144 lines (136 loc) · 5.41 KB
/
sgyb.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
// ==UserScript==
// @name XJTU 四个一百自动化脚本(仅含书籍和教师模块)
// @namespace http://tampermonkey.net/
// @version 1.0
// @description 调用ChatGPT生成读后感批量补录XJTU 100本经典阅读,批量确认教师
// @author Miracle24
// @match http://nsa.xjtu.edu.cn/sgyb/ybbsplpj*
// @match http://nsa.xjtu.edu.cn/sgyb/ybmjsplpj*
// @icon https://www.google.com/s2/favicons?sz=64&domain=xjtu.edu.cn
// @grant none
// @license MIT
// ==/UserScript==
async function query(title, apikey){
const res = await fetch("https://api.openai.com/v1/completions", {
method: "POST",
headers: {
"Content-Type": "application/json",
authorization: `Bearer ${apikey}`,
},
body: JSON.stringify({
model: "text-davinci-003",
prompt: `请对${title}一书给出500字左右的读书感想`,
max_tokens: 600,
temperature: 0,
}),
});
const response = await res.json();
const result = response.choices[0].text;
return result;
}
(function() {
'use strict';
// Your code here...
const controlPanel = document.createElement("div");
if(window.location.pathname.includes("ybbsplpj")){ //一百本书
controlPanel.innerHTML = `
<style>
.control-panel{
position: fixed;
top: 0;
left: 50%;
min-height: 40px;
min-width: 300px;
border-radius: 0 0 12px 12px;
transform: translateX(-50%);
background-color: rgb(219, 219, 219);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
z-index: 1000;
text-align: center;
line-height: 40px;
padding: 0 12px;
}
</style>
<div class="control-panel">
<div>
<span>API Key(需要科学上网)</span>
<input type="text" id="apikey">
</div>
<div>
直接使用书名作为评价(无需API Key)
<input type="checkbox" id="switch">
</div>
<button id="fillButton">批量补录</button>
<span id="finish">已完成:0</span>
<button id="saveButton">一键保存</button>
<div>
`;
document.body.insertBefore(controlPanel, null);
document.getElementById("fillButton").onclick = async function(){
const apikey = document.getElementById("apikey").value;
const useBookName = document.getElementById("switch").checked;
if(apikey === "" && useBookName == false){
alert("api key 不能为空");
return;
}
for(var i = 0; i < 100; i ++){
var bookBox = document.getElementById(i.toString());
if (bookBox == undefined) break;
var bookTitle = bookBox.getElementsByClassName("tit")[0].getElementsByClassName("el-form-item__content")[0].getElementsByTagName("span")[0].textContent;
var bookComment = bookBox.getElementsByTagName("textarea")[0];
if (useBookName == true){
bookComment.value = bookTitle;
}
else{
bookComment.value = await query(bookTitle, apikey);
}
document.getElementById("finish").textContent = `已完成:${i+1}`;
};
};
document.getElementById("saveButton").onclick = function(){
for(var i = 0; i < 100; i ++){
var bookBox = document.getElementById(i.toString());
if (bookBox == undefined) break;
const saveButton = bookBox.getElementsByClassName("operation")[0].getElementsByTagName("button")[0];
if (saveButton.textContent === "保存"){
saveButton.click();
}
};
};
}
else if(window.location.pathname.includes("ybmjsplpj")){ //一百名教师
controlPanel.innerHTML = `
<style>
.control-panel{
position: fixed;
top: 0;
left: 50%;
min-height: 40px;
min-width: 300px;
border-radius: 0 0 12px 12px;
transform: translateX(-50%);
background-color: rgb(219, 219, 219);
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
z-index: 1000;
text-align: center;
line-height: 40px;
padding: 0 12px;
}
</style>
<div class="control-panel">
<button id="saveButton">一键保存</button>
<div>
`;
document.body.insertBefore(controlPanel, null);
document.getElementById("saveButton").onclick = function(){
for(var i = 0; i < 100; i ++){
var teacherBox = document.getElementById(i.toString());
if (teacherBox == undefined) break;
const saveButton = teacherBox.getElementsByClassName("operation")[0].getElementsByTagName("button")[0];
if (saveButton.textContent === "保存"){
saveButton.click();
}
};
};
}
})();