Skip to content

Instantly share code, notes, and snippets.

@MohamedElashri
Created October 2, 2023 12:08
Show Gist options
  • Select an option

  • Save MohamedElashri/1e26d3a18ce263c2110b7f81a586f791 to your computer and use it in GitHub Desktop.

Select an option

Save MohamedElashri/1e26d3a18ce263c2110b7f81a586f791 to your computer and use it in GitHub Desktop.
Userscript for auto clicking Continue generating button for ChatGPT
// ==UserScript==
// @name Auto Continue for ChatGPT
// @namespace http://melashri.net
// @version 0.1
// @description Automatically clicks "Continue generating" button on OpenAI's ChatGPT website.
// @author Mohamed Elashri
// @match https://chat.openai.com/*
// @grant none
// ==/UserScript==
function waitForButtonAndClick() {
const buttonText = "Continue generating";
let buttonClicked = false;
const observer = new MutationObserver((mutationsList) => {
if (buttonClicked) {
return;
}
for (const mutation of mutationsList) {
if (mutation.addedNodes) {
for (const node of mutation.addedNodes) {
if (
node.tagName === 'BUTTON' &&
node.textContent.includes(buttonText)
) {
const button = node;
buttonClicked = true;
// Disconnect observer temporarily
observer.disconnect();
setTimeout(() => {
// Reconnect observer after delay
observeChanges();
buttonClicked = false;
try{
// Attempt to click on the found element.
console.log("Clicking on: ", buttonText);
button.click();
} catch(e){
// Log any error that occurs during the click event.
console.error("Error clicking on: ", buttonText, e);
}
return;
}, 1000); // Increase this delay if needed
}
}
}
}
});
const observeChanges = () => {
observer.observe(document.body, { childList: true, subtree: true });
};
observeChanges();
}
waitForButtonAndClick();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment