I failed to fix it, and I thought: "Hey bud, you've stopped searching with google since long, you know ctrl+c, ctrl+v and duckduckgo is cooler. Make a new script!"
This is what i came up with:
Code: Select all
FeelingDucky(text, site="")
{
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := false ; This is known to work incorrectly on IE7.
StringReplace, Text, Text, `%, `%25, All
FormatInteger := A_FormatInteger, FoundPos := 0
SetFormat, IntegerFast, Hex
While, FoundPos := RegExMatch(Text,"S)[^\w-\.~%]",Char,FoundPos + 1)
StringReplace, Text, Text, %Char%, % "%" . SubStr("0" . SubStr(Asc(Char),3),-1), All
SetFormat, IntegerFast, %FormatInteger%
site := site ? ("site:" site " "): ""
wb.Navigate("http://duckduckgo.com/?q=\" . site . Text)
IELoad(wb,10)
sleep, 10
IELoad(wb,10)
r := wb.LocationURL
wb.Quit()
return r
}
IELoad(wb,sl=100)
{
If !wb
return
while not wb.busy
Sleep %sl%
while wb.busy
Sleep %sl%
}
(Thanks SKAN for the inspiration)
Code: Select all
lstSites= ; SiteName | SearchSiteURL
( ; ----------------+-----------------------------------------------
IMDb | imdb.com/title
OpenSubtitles | opensubtitles.org/en/search/sublanguageid-eng
Addic7ed | addic7ed.com/show
TVSubtitles | www.tvsubtitles.net/tvshow
AutoHotkey | autohotkey.com
MSDN | msdn.microsoft.com/en-us/library
Wikipedia | en.wikipedia.org/wiki
Dictionary | dictionary.reference.com/browse
UrbanDict | urbandictionary.com/define.php?term=
) ; ----------------^-----------------------------------------------
StringSplit, BTN, lstSites, `n, %A_Space%
oSites := {}
Loop % ( BTN0 ) {
StringSplit, Par, BTN%A_Index%, |, %A_Space%
oSites.Insert(Par1, Par2)
ddlSites .= (!ddlSites ? par1 "|" : "|"par1)
}
Gui, duck:Default
Gui, +AlwaysOnTop +ToolWindow
hGui := WinExist()
Gui, Add, Edit, w400 vcSearch,
Gui, Add, DropDownList,wp xp y+10 vcSites,% ddlSites
Gui, Add, Button, Default y+10 wp h100 xp gSearch, I'm Feeling Ducky!
Gui, Show, AutoSize, I'm Feeling Ducky!
return
Search:
GuiControlGet, selectedSite,,cSites
GuiControlGet, searchText,,cSearch
if (searchText="") && (selectedSite="")
{
Run, http://duckduckgo.com
return
}
if (searchText="") && (selectedSite!="")
Run,% "http://" oSites[selectedSite]
else
Run,% FeelingDucky(searchText,oSites[selectedSite])
return
duckGuiEscape:
duckGuiClose:
ExitApp
FeelingDucky(text, site="")
{
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := false ; This is known to work incorrectly on IE7.
StringReplace, Text, Text, `%, `%25, All
FormatInteger := A_FormatInteger, FoundPos := 0
SetFormat, IntegerFast, Hex
While, FoundPos := RegExMatch(Text,"S)[^\w-\.~%]",Char,FoundPos + 1)
StringReplace, Text, Text, %Char%, % "%" . SubStr("0" . SubStr(Asc(Char),3),-1), All
SetFormat, IntegerFast, %FormatInteger%
site := site ? ("site:" site " "): ""
wb.Navigate("http://duckduckgo.com/?q=\" . site . Text)
IELoad(wb,10)
sleep, 10
IELoad(wb,10)
r := wb.LocationURL
wb.Quit()
return r
}
IELoad(wb,sl=100)
{
If !wb
return
while not wb.busy
Sleep %sl%
while wb.busy
Sleep %sl%
}