1
0
mirror of https://github.com/lencx/ChatGPT.git synced 2024-10-01 01:06:13 -04:00

fix: auto continue

This commit is contained in:
lencx 2023-07-05 19:11:14 +08:00
parent 94d27f0d24
commit c499ba37bd
2 changed files with 17 additions and 15 deletions

30
scripts/chat.js vendored
View File

@ -1,6 +1,6 @@
/** /**
* @name chat.js * @name chat.js
* @version 0.1.2 * @version 0.1.3
* @url https://github.com/lencx/ChatGPT/tree/main/scripts/chat.js * @url https://github.com/lencx/ChatGPT/tree/main/scripts/chat.js
*/ */
@ -151,10 +151,10 @@ function chatInit() {
function autoContinue() { function autoContinue() {
// Create an instance of the observer // Create an instance of the observer
const observer = new MutationObserver((mutationsList, observer) => { const observer = new MutationObserver((mutationsList) => {
for (let mutation of mutationsList) { for (let mutation of mutationsList) {
if (mutation.type === 'childList') { if (mutation.type === 'childList') {
const btn = [...mutation.target.querySelectorAll('button.btn')].find((btn) => const btn = Array.from(mutation.target.querySelectorAll('button.btn')).find((btn) =>
btn.innerText.includes('Continue generating'), btn.innerText.includes('Continue generating'),
); );
@ -170,19 +170,21 @@ function chatInit() {
} }
}); });
// Start observing the dom change of the form // Wait until the form exists
observer.observe(document.forms[0], { const interval = setInterval(() => {
attributes: false, if (document.forms[0]) {
childList: true, // Start observing the dom change of the form
subtree: true, observer.observe(document.forms[0], {
}); attributes: false,
childList: true,
subtree: true,
});
clearInterval(interval); // Stop checking when the form exists
}
}, 1000);
} }
init(); init();
} }
if (document.readyState === 'complete' || document.readyState === 'interactive') { document.addEventListener('DOMContentLoaded', chatInit);
chatInit();
} else {
document.addEventListener('DOMContentLoaded', chatInit);
}

View File

@ -6,7 +6,7 @@
"scripts": [ "scripts": [
{ {
"name": "chat.js", "name": "chat.js",
"version": "0.1.2" "version": "0.1.3"
}, },
{ {
"name": "cmd.js", "name": "cmd.js",