关轮询

This commit is contained in:
Bluemangoo 2025-05-08 20:21:41 +08:00
parent e28793ac5b
commit cb6c5459e1
Signed by: Bluemangoo
GPG Key ID: F2F7E46880A1C4CF

View File

@ -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);
})();