Skip to content

Commit

Permalink
Replaced sub-second interval funcs w/ timer ones to avoid potential o…
Browse files Browse the repository at this point in the history
…verlaps
  • Loading branch information
adamlui committed May 17, 2024
1 parent edc6d19 commit 0f747a9
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions chatgpt.js
Original file line number Diff line number Diff line change
Expand Up @@ -1048,10 +1048,11 @@ const chatgpt = { // eslint-disable-line no-redeclare

isIdle: function() {
return new Promise(resolve => {
const intervalId = setInterval(() => {
if (chatgpt.getRegenerateButton()) {
clearInterval(intervalId); resolve(true);
}}, 100);});},
(function checkIsIdle() {
if (chatgpt.getRegenerateButton()) resolve(true);
else setTimeout(checkIsIdle, 100);
})();
});},

isLoaded: function() {
return new Promise(resolve => {
Expand Down Expand Up @@ -1496,12 +1497,12 @@ const chatgpt = { // eslint-disable-line no-redeclare
sendButton = document.querySelector('form button[class*="bottom"]');
textArea.value = msg;
textArea.dispatchEvent(new Event('input', { bubbles: true })); // enable send button
const delaySend = setInterval(() => {

setTimeout(function delaySend() {
if (!sendButton?.hasAttribute('disabled')) { // send msg
method.toLowerCase() == 'click' || chatgpt.browser.isMobile() ? sendButton.click()
: textArea.dispatchEvent(new KeyboardEvent('keydown', { keyCode: 13, bubbles: true }));
clearInterval(delaySend);
}
} else setTimeout(delaySend, 25);
}, 25);
},

Expand Down

0 comments on commit 0f747a9

Please sign in to comment.