How to search with chatgpt from clipboard for meaning

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

How to search with chatgpt from clipboard for meaning

21 Feb 2023, 21:58

I have been doing this to check meaning of a word or phrase.

Code: Select all

+y::
{
	Send, ^c
	Sleep 50
	Run, http://www.google.com/search?q=`%22%clipboard%`%22
	Return
}
How can I make it work with https://chat.openai.com/chat?
I don't know how to make it as a link to search.
aliztori
Posts: 119
Joined: 19 Jul 2022, 12:44

Re: How to search with chatgpt from clipboard for meaning

22 Feb 2023, 03:34

Chatgpt has a humanity detection process and I don't think this is possible now
anhnha
Posts: 116
Joined: 08 Aug 2018, 02:46

Re: How to search with chatgpt from clipboard for meaning

22 Feb 2023, 13:41

aliztori wrote:
22 Feb 2023, 03:34
Chatgpt has a humanity detection process and I don't think this is possible now
I have seen many people used them in chrome extensions. So should it work?
https://github.com/wong2/chatgpt-google-extension#readme
telenaco
Posts: 3
Joined: 02 Mar 2023, 11:22

Re: How to search with chatgpt from clipboard for meaning

02 Mar 2023, 11:27

I slap some code together using the chrome.ahk, checkout this video the link to the github is there too https://www.youtube.com/watch?v=FxF_0KC8QrQ I have not used javascript before so the code might look like an abomination
telenaco
Posts: 3
Joined: 02 Mar 2023, 11:22

Re: How to search with chatgpt from clipboard for meaning

02 Mar 2023, 11:50

I might just share the code in here:

Code: Select all

#NoEnv
#SingleInstance, Force
SetBatchLines, -1
SetTitleMatchMode 2
SendMode, Input
SetWorkingDir, %A_ScriptDir%
#Include ../Chrome.ahk
 
; run chrome.exe "--remote-debugging-port=9222"

url := "https://chat.openai.com/"
 
if WinExist("ahk_exe chrome.exe") {
   ; Chrome is running, activate the window
   WinActivate, ahk_exe chrome.exe
}else  {
   ; Chrome is not running, start it with the remote debugging flag
   Run, chrome.exe --remote-debugging-port=9222
   ; Wait for Chrome to start
   Sleep, 5000
}
 
 
if (Chromes := Chrome.FindInstances())
ChromeInst := {"base": Chrome, "DebugPort": Chromes.MinIndex()} ; or if you know the port:  ChromeInst := {"base": Chrome, "DebugPort": 9222}
else
   msgbox That didn't work. Please check if Chrome is running in debug mode.`n(use, for example, http://localhost:9222/json/version )
 
 
; --- Connect to the page ---
if !(Page := ChromeInst.GetPage( ))     
{
   MsgBox, Could not retrieve page!
   ChromeInst.Kill()
}
else
   Page.WaitForLoad()
 
 
Page.Call("Page.navigate", {"url": url})   
Page.WaitForLoad()

^F2:: ; ^ is the equivalent on autohotkey to pressing the crtl key + F2 change this to whatever suits you

; Send Ctrl+C to copy the selected text
SendInput, {Ctrl Down}c{Ctrl Up}

; Execute a JavaScript code snippet to retrieve the text box element with the specified class name
Page.Evaluate("var textBox = document.getElementsByClassName('m-0 w-full resize-none border-0 bg-transparent p-0 pl-2 pr-7 focus:ring-0 focus-visible:ring-0 dark:bg-transparent md:pl-0')[0];")

; Set the value of the text box to the clipboard text
Page.Evaluate("textBox.value = '" StrReplace(Clipboard, "'", "\'") "';")
;Page.Evaluate("textBox.value = '" Clipboard "';")


; Execute a JavaScript code snippet to submit the form
Page.Evaluate("var event = new KeyboardEvent('keydown', {key: 'Enter', code: 'Enter', keyCode: 13, which: 13, bubbles: true, cancelable: true});")
Page.Evaluate("textBox.dispatchEvent(event);")

MsgBox, 4100, Generating response, Press Esc or Enter when done
IfMsgBox OK
{
    ;code here when pressing enter
    ;holding the code here till the response is complete
    ;otherwise the div has no text
}

; Execute a JavaScript code snippet to retrieve the elements with the specified class name
Page.Evaluate("var divs = document.getElementsByClassName('markdown prose w-full break-words dark:prose-invert light');")
 
; Get the last div element in the array
Page.Evaluate("var lastDiv = divs[divs.length - 1];")
 
; Get the inner text of the last div element
lastDivText := Page.Evaluate("lastDiv.innerText").value

Clipboard:= lastDivText
 
; Display the inner text of the last div element in a message box
; MsgBox, % "The text inside the last div element is: " lastDivText
 
return

You neeed the chrome.ahk for that to work, I upload an extra file on the example you can find it here https://github.com/telenaco/autohotkeyChatGPT

I just created a new post, I hope is on the right section, viewtopic.php?f=76&t=114599 to see how could I get the response automatically on the clipboard as now I have to press enter on a message box to copy the response.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], bobstoner289, Chunjee, macromint, peter_ahk and 319 guests