Created
April 17, 2024 13:14
-
-
Save happylinks/f328431a02d754aa66fa02fa92fad60f to your computer and use it in GitHub Desktop.
Revisions
-
happylinks renamed this gist
Apr 17, 2024 . 1 changed file with 0 additions and 0 deletions.There are no files selected for viewing
File renamed without changes. -
happylinks created this gist
Apr 17, 2024 .There are no files selected for viewing
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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,36 @@ 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); });