Search in google depending on whether what is selected is a text or a URL
Posted: 13 Jan 2022, 17:14
If a normal text is selected, it will search google normally, but if a url is selected, it will go directly to the page.
Code: Select all
!g::
port:=Clipboard
Send, ^c ;Ctrl C
Sleep, 100
Run, % (clip := Trim(clipboard)) ~= "^(https?://)?([\w\d]([\w\d]|(-[\w\d]))*\.)+\w+(/\S*)?$"
? (clip ~= "^(https?://|www\.)" ? "" : "http://") . clip
: "https://www.google.com/search?q=" . fix(clip)
Return
fix(url)
{
RegExMatch(url, "^(https?://)?(.+?)(/)?$", part)
Loop, Parse, part2
text .= A_LoopField ~= "[$&+,:;@""<>`%{}|\\^~[\] `]" ? Format("%{:X}", Asc(A_LoopField)) : A_LoopField
Return part1 text part3
}
Clipboard := port