关轮询
This commit is contained in:
parent
e28793ac5b
commit
cb6c5459e1
@ -19,7 +19,17 @@
|
||||
id: ""
|
||||
};
|
||||
|
||||
async function poll() {
|
||||
class Poll {
|
||||
polling = true;
|
||||
|
||||
constructor() {
|
||||
this.poll();
|
||||
}
|
||||
|
||||
async poll() {
|
||||
if (!this.polling) {
|
||||
return;
|
||||
}
|
||||
let res;
|
||||
try {
|
||||
res = await fetch(`${HOST}/polling?env=course`, {
|
||||
@ -44,6 +54,7 @@
|
||||
console.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getAnswerElement() {
|
||||
const doc = document
|
||||
@ -71,7 +82,7 @@
|
||||
if (id !== question.id) {
|
||||
return;
|
||||
}
|
||||
aiButton.value = "?"
|
||||
aiButton.value = "?";
|
||||
const answers = answer.split("\n");
|
||||
const children = getAnswerElement().children[0].children;
|
||||
for (const child of children) {
|
||||
@ -108,6 +119,7 @@
|
||||
};
|
||||
|
||||
let aiButton;
|
||||
let poll;
|
||||
|
||||
function createButton(addAiButton = false) {
|
||||
const base = document.getElementById("mainFrame");
|
||||
@ -140,9 +152,19 @@
|
||||
|
||||
function initAiBridge() {
|
||||
createButton(true);
|
||||
poll();
|
||||
if (poll) {
|
||||
poll.polling = false;
|
||||
}
|
||||
poll = new Poll();
|
||||
}
|
||||
|
||||
function stopPolling() {
|
||||
if (poll) {
|
||||
poll.polling = false;
|
||||
}
|
||||
}
|
||||
|
||||
GM_registerMenuCommand("添加复制按钮", createButton);
|
||||
GM_registerMenuCommand("初始化ai桥", initAiBridge);
|
||||
GM_registerMenuCommand("停止轮询", stopPolling);
|
||||
})();
|
||||
|
Loading…
x
Reference in New Issue
Block a user