Skip to content

Instantly share code, notes, and snippets.

@ifvictr
Last active March 6, 2024 20:23
Show Gist options
  • Save ifvictr/61ba480dd85152b740cf14f59b8dc38c to your computer and use it in GitHub Desktop.
Save ifvictr/61ba480dd85152b740cf14f59b8dc38c to your computer and use it in GitHub Desktop.

Revisions

  1. ifvictr revised this gist Mar 6, 2024. 1 changed file with 5 additions and 2 deletions.
    7 changes: 5 additions & 2 deletions content.js
    Original file line number Diff line number Diff line change
    @@ -16,11 +16,14 @@ window.addEventListener('load', () => {
    // We can only send after the main page content renders
    const observer = new MutationObserver(() => {
    const isFormLoaded = document.querySelector('form') !== null
    const isNewChat = window.location.pathname === '/'
    const isMessageHistoryLoaded =
    document.querySelector('div[class^="react-scroll-to-bottom"]') !== null // Needed to be able to send in existing chats
    if (isFormLoaded && isMessageHistoryLoaded) {
    if (
    isFormLoaded &&
    (isNewChat || (!isNewChat && isMessageHistoryLoaded))
    ) {
    observer.disconnect()

    sendMessage(query)
    }
    })
  2. ifvictr revised this gist Sep 1, 2023. 1 changed file with 4 additions and 0 deletions.
    4 changes: 4 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -2,6 +2,10 @@

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

    ## Demo

    Video here: https://twitter.com/ifvictr/status/1695141929535811821

    ## Setup

    The setup for this consists of two parts: creating the Boost and creating the search shortcut.
  3. ifvictr revised this gist Aug 25, 2023. 1 changed file with 17 additions and 15 deletions.
    32 changes: 17 additions & 15 deletions content.js
    Original file line number Diff line number Diff line change
    @@ -9,19 +9,21 @@ function sendMessage(message) {
    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 renders
    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()
    window.addEventListener('load', () => {
    const params = new URLSearchParams(window.location.search)
    const query = params.get('q')
    if (query) {
    // We can only send after the main page content renders
    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 })
    }
    sendMessage(query)
    }
    })
    observer.observe(document.body, { childList: true, subtree: true })
    }
    })
  4. ifvictr revised this gist Aug 25, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion content.js
    Original file line number Diff line number Diff line change
    @@ -12,7 +12,7 @@ function sendMessage(message) {
    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
    // We can only send after the main page content renders
    const observer = new MutationObserver(() => {
    const isFormLoaded = document.querySelector('form') !== null
    const isMessageHistoryLoaded =
  5. ifvictr revised this gist Aug 25, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@ The setup for this consists of two parts: creating the Boost and creating the se

    ### Creating the Boost

    1. Go to `arc://boost/new` and select the "Inject" template.
    1. Go to `arc://boost/new` (or enter `New Legacy Boost (Advanced)` in the Command Bar) 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. Delete the example code from the Boost editor, then replace it with the contents of [`content.js`](https://gist.github.com/ifvictr/61ba480dd85152b740cf14f59b8dc38c#file-content-js).
    4. (Optional) Click on the gear icon on the top-left corner and name the Boost "ChatGPT Search Helper".
  6. ifvictr revised this gist Aug 25, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,6 @@
    # ChatGPT Search Helper

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

    ## Setup

  7. ifvictr revised this gist Aug 25, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ The setup for this consists of two parts: creating the Boost and creating the se

    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`](https://gist.github.com/ifvictr/61ba480dd85152b740cf14f59b8dc38c#file-content-js) and paste it into the Boost editor.
    3. Delete the example code from the Boost editor, then replace it with the contents of [`content.js`](https://gist.github.com/ifvictr/61ba480dd85152b740cf14f59b8dc38c#file-content-js).
    4. (Optional) Click on the gear icon on the top-left corner and name the Boost "ChatGPT Search Helper".

    ### Creating the search shortcut
  8. ifvictr revised this gist Aug 25, 2023. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion README.md
    Original file line number Diff line number Diff line change
    @@ -10,7 +10,7 @@ The setup for this consists of two parts: creating the Boost and creating the se

    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.
    3. Copy the contents of [`content.js`](https://gist.github.com/ifvictr/61ba480dd85152b740cf14f59b8dc38c#file-content-js) 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 search shortcut
  9. ifvictr revised this gist Aug 25, 2023. 1 changed file with 4 additions and 4 deletions.
    8 changes: 4 additions & 4 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,7 @@ 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.
    The setup for this consists of two parts: creating the Boost and creating the search shortcut.

    ### Creating the Boost

    @@ -13,8 +13,8 @@ The setup for this consists of two parts: creating the boost and creating the sh
    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
    ### Creating the search 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.
    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 chose "ChatGPT" and "c". Click "Add" afterwards.
    3. It is done! You can now use the shortcut you made to message ChatGPT from your Command Bar.
  10. ifvictr revised this gist Aug 25, 2023. 1 changed file with 20 additions and 0 deletions.
    20 changes: 20 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,20 @@
    # 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.
  11. ifvictr created this gist Aug 25, 2023.
    27 changes: 27 additions & 0 deletions content.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,27 @@
    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 })
    }