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