Created
April 17, 2024 13:14
-
-
Save happylinks/f328431a02d754aa66fa02fa92fad60f to your computer and use it in GitHub Desktop.
Interrupt ChatGPT when it's typing and you just want to send something else without clicking stop first
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
document.addEventListener("DOMContentLoaded", (event) => { | |
function handleElementAppeared(textarea) { | |
console.log(textarea); | |
textarea.addEventListener("keydown", e => { | |
if (e.key === "Enter") { | |
var stopButton = document.querySelector('[aria-label="Stop generating"]'); | |
if (stopButton) { | |
stopButton.click(); | |
textarea.submit(); | |
} | |
} | |
}); | |
}; | |
const config = { childList: true, subtree: true }; | |
const callback = function(mutationsList, observer) { | |
for (const mutation of mutationsList) { | |
if (mutation.addedNodes.length > 0) { | |
mutation.addedNodes.forEach(node => { | |
if (node.id === 'prompt-textarea') { | |
handleElementAppeared(node); | |
} else if (node.querySelector) { | |
let targetElement = node.querySelector('#prompt-textarea'); | |
if (targetElement) { | |
handleElementAppeared(targetElement); | |
} | |
} | |
}); | |
} | |
} | |
}; | |
const observer = new MutationObserver(callback); | |
observer.observe(document.body, config); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment