Last active
June 29, 2023 06:11
-
-
Save benwoodward/d74e6615d47f5967b144396c9ae4e5ec to your computer and use it in GitHub Desktop.
Arc Boost that clicks GPT4 button every time in ChatGPT, triggered by typing in prompt textarea (written by ChatGPT) - create a new boost, click the button to add code, paste this into the JS section
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
// Debounce function | |
function debounce(func, wait) { | |
let timeout; | |
return function() { | |
const context = this, args = arguments; | |
const later = function() { | |
timeout = null; | |
func.apply(context, args); | |
}; | |
clearTimeout(timeout); | |
timeout = setTimeout(later, wait); | |
}; | |
} | |
function isElementInViewport(el) { | |
const rect = el.getBoundingClientRect(); | |
return ( | |
rect.top >= 0 && | |
rect.left >= 0 && | |
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && | |
rect.right <= (window.innerWidth || document.documentElement.clientWidth) | |
); | |
} | |
// Debounced button click logic | |
const debouncedButtonClick = debounce(function() { | |
const buttons = Array.from(document.querySelectorAll('button')).filter(btn => btn.id.includes('radix')); | |
const gpt4Button = buttons[1]; // Get the second button. | |
if (gpt4Button) { | |
const gptButtonDiv = gpt4Button.querySelector('.group\\/button'); | |
if (gptButtonDiv && isElementInViewport(gptButtonDiv)) { | |
gptButtonDiv.click(); | |
// Refocus the textarea after clicking the GPT-4 button | |
const textarea = document.querySelector('#prompt-textarea'); | |
if (textarea) { | |
textarea.focus(); | |
} | |
} | |
} | |
}, 500); // Wait 500ms after the last call to run the function | |
// Function to add event listener to the text area | |
function addFocusListenerToTextArea() { | |
const textArea = document.querySelector('#prompt-textarea'); | |
if (textArea) { | |
textArea.addEventListener('input', debouncedButtonClick); | |
} | |
} | |
// Call addFocusListenerToTextArea every 500ms until the text area is found | |
setInterval(addFocusListenerToTextArea, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment