-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.ahk
66 lines (56 loc) · 1.8 KB
/
search.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
; # Win (Windows logo key)
; ! Alt
; ^ Ctrl
; + Shift
; & An ampersand may be used between any two keys or mouse buttons to combine them into a custom hotkey.
#NoEnv
#NoTrayIcon
#SingleInstance
UrlEscape( url, flags )
{
VarSetCapacity( newUrl, 4096, 0 ), pcche := 4096
DllCall( "shlwapi\UrlEscapeW", Str, url, Str, newUrl, UIntP, pcche, UInt, flags )
Return newUrl
}
UrlUnEscape( url, flags )
{
VarSetCapacity( newUrl, 4096, 0 ), pcche := 4096
DllCall( "shlwapi\UrlUnescapeW", Str, url, Str, newUrl, UIntP, pcche, UInt, flags )
Return newUrl
}
; URL with %s in place of query
OpenURL(url)
{
prevClipboard := ClipboardAll
Clipboard =
Send, ^c
ClipWait
query := Trim(Clipboard)
if SubStr(query, 1, 4)="http" OR SubStr(query, 1, 3)="www" {
Run, %query%
return
}
escapedQuery := UrlEscape( RegExReplace(RegExReplace(query, "\r?\n", " "), "(^\s+|\s+$)"), 0x00080000 | 0x00002000 | 0x00001000)
toSearch := "%s"
asdf := StrReplace(url, toSearch, escapedQuery)
Run, %asdf%
Clipboard := prevClipboard
}
#+w::
OpenURL("https://translate.yandex.com/?&text=%s")
return
#q::
OpenUrl("https://www.google.com/search?q=%s")
return
custom := ""
#^q:: ; Search in Google with additional custom query
copy := custom
copy := UrlEscape( RegExReplace(RegExReplace(copy, "\r?\n", " "), "(^\s+|\s+$)", " "), 0x00080000 | 0x00002000 | 0x00001000)
OpenUrl("https://www.google.com/search?q=%s%20" . copy)
return
#+^q:: ; Search in Google with additional new custom query
InputBox, custom, "Enter additional query for future searches"
copy := custom
copy := UrlEscape( RegExReplace(RegExReplace(copy, "\r?\n", " "), "(^\s+|\s+$)", " "), 0x00080000 | 0x00002000 | 0x00001000)
OpenUrl("https://www.google.com/search?q=%s%20" . copy)
return