From c499ba37bdd81e37ed1856570778962bb3a44fe4 Mon Sep 17 00:00:00 2001 From: lencx Date: Wed, 5 Jul 2023 19:11:14 +0800 Subject: [PATCH] fix: auto continue --- scripts/chat.js | 30 ++++++++++++++++-------------- scripts/manifest.json | 2 +- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/scripts/chat.js b/scripts/chat.js index 20cbadf..80726a0 100644 --- a/scripts/chat.js +++ b/scripts/chat.js @@ -1,6 +1,6 @@ /** * @name chat.js - * @version 0.1.2 + * @version 0.1.3 * @url https://github.com/lencx/ChatGPT/tree/main/scripts/chat.js */ @@ -151,10 +151,10 @@ function chatInit() { function autoContinue() { // Create an instance of the observer - const observer = new MutationObserver((mutationsList, observer) => { + const observer = new MutationObserver((mutationsList) => { for (let mutation of mutationsList) { 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'), ); @@ -170,19 +170,21 @@ function chatInit() { } }); - // Start observing the dom change of the form - observer.observe(document.forms[0], { - attributes: false, - childList: true, - subtree: true, - }); + // Wait until the form exists + const interval = setInterval(() => { + if (document.forms[0]) { + // Start observing the dom change of the form + observer.observe(document.forms[0], { + attributes: false, + childList: true, + subtree: true, + }); + clearInterval(interval); // Stop checking when the form exists + } + }, 1000); } init(); } -if (document.readyState === 'complete' || document.readyState === 'interactive') { - chatInit(); -} else { - document.addEventListener('DOMContentLoaded', chatInit); -} +document.addEventListener('DOMContentLoaded', chatInit); diff --git a/scripts/manifest.json b/scripts/manifest.json index a90313d..0b73931 100644 --- a/scripts/manifest.json +++ b/scripts/manifest.json @@ -6,7 +6,7 @@ "scripts": [ { "name": "chat.js", - "version": "0.1.2" + "version": "0.1.3" }, { "name": "cmd.js",