Skip to content

Instantly share code, notes, and snippets.

@ifvictr
Last active March 6, 2024 20:23
Show Gist options
  • Select an option

  • Save ifvictr/61ba480dd85152b740cf14f59b8dc38c to your computer and use it in GitHub Desktop.

Select an option

Save ifvictr/61ba480dd85152b740cf14f59b8dc38c to your computer and use it in GitHub Desktop.
An Arc boost that lets you message ChatGPT from the Command Bar.

ChatGPT Search Helper

An Arc Boost that lets you message ChatGPT directly from the Command Bar.

Setup

The setup for this consists of two parts: creating the boost and creating the shortcut.

Creating the Boost

  1. Go to arc://boost/new and select the "Inject" template.
  2. When asked what you want to boost, select "A specific website" and enter chat.openai.com. Then, click "Create Boost".
  3. Copy the contents of content.js from this Gist and paste it into the Boost editor.
  4. (Optional) Click on the gear icon on the top-left corner and name the Boost "ChatGPT Search Helper".

Creating the shortcut

  1. Go to arc://settings/searchEngines.
  2. Next to "Site search", click "Add". In the field under "URL with %s in place of query", enter https://chat.openai.com/?q=%s. Choose whatever name and shortcut you like. Personally, I went with "ChatGPT" and "c". Click "Add" afterwards.
  3. It is done! You can start messaging ChatGPT from your Command Bar now.
function sendMessage(message) {
const form = document.querySelector('form')
const textarea = form.querySelector('textarea')
textarea.value = message
textarea.dispatchEvent(new Event('input', { bubbles: true })) // Prevent message from being immediately cleared
const sendButton = form.querySelector('textarea + button')
sendButton.click()
}
const params = new URLSearchParams(window.location.search)
const query = params.get('q')
if (query) {
// We can only send after the main page content has loaded
const observer = new MutationObserver(() => {
const isFormLoaded = document.querySelector('form') !== null
const isMessageHistoryLoaded =
document.querySelector('div[class^="react-scroll-to-bottom"]') !== null // Needed to be able to send in existing chats
if (isFormLoaded && isMessageHistoryLoaded) {
observer.disconnect()
sendMessage(query)
}
})
observer.observe(document.body, { childList: true, subtree: true })
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment