Skip to content

Instantly share code, notes, and snippets.

@happylinks
Created April 17, 2024 13:14
Show Gist options
  • Save happylinks/f328431a02d754aa66fa02fa92fad60f to your computer and use it in GitHub Desktop.
Save happylinks/f328431a02d754aa66fa02fa92fad60f to your computer and use it in GitHub Desktop.

Revisions

  1. happylinks renamed this gist Apr 17, 2024. 1 changed file with 0 additions and 0 deletions.
  2. happylinks created this gist Apr 17, 2024.
    36 changes: 36 additions & 0 deletions chatgpt interrupt arc boost
    Original 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);
    });