Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Google Suggest


  • Please log in to reply
5 replies to this topic
keyboardfreak
  • Members
  • 217 posts
  • Last active: Sep 27 2010 07:21 PM
  • Joined: 09 Oct 2004
This script really needs some cleanup, no hotkey is assigned, no comments, etc. but I'm really lazy, so I post it here as is.

Run the script, type something into the input field and see what happens.
suggestURL := "http://www.google.com/complete/search?hl=en&js=true&qu="
searchURL := "http://www.google.com/search?client=opera&rls=en&sourceid=opera&ie=utf-8&oe=utf-8&q="
tempfile = %temp%\suggest


settimer, timer, 1000

oldinput = 

Gui, Add, Edit, x6 y11 w400 h22, 
Gui, Add, ListView, x6 y35 w400 h250, Query|Number of results
Gui, Add, Button, Default gGo, &Go
Gui, Show, Center h320 w413, Google Suggest



timer:
  guicontrolget, text,, Edit1
  if (text = oldinput)
    return
  
  LV_Delete()
  oldinput := text
  
  if (text = "")
    return  

  query := EncodeURL(text)
  urldownloadtofile, %suggestURL%%query%, %tempfile%
  fileread, suggestions, %tempfile%
  FileDelete, %tempfile%
  
  beginstr = new Array(
  len := strlen(beginstr)

  pos := instr(suggestions, beginstr)
  pos := pos  + len

  endpos := instr(suggestions, ")", true, pos)

  stringmid, results, suggestions, % pos, % endpos - pos
  
  result_to_array(results, "results")
  
  pos := instr(suggestions, beginstr, true, endpos)
  pos := pos  + len
  
  endpos := instr(suggestions, ")", true, pos)

  stringmid, resultnums, suggestions, % pos, % endpos - pos
  
  result_to_array(resultnums, "resultnums")
  
  options = Select

  loop, % numresults
  {
    query := results%a_index%
    num := resultnums%a_index%
    LV_Add(options, query, num)
    options =
  }

  LV_ModifyCol()
 
  return
  

guiescape:
  gui, hide
  return
  
  
Go:
  Gui, submit
  
  selected := LV_GetNext()
    
  if (selected = 0)
    msgbox, no query
  else
  {
    LV_GetText(selection, selected)
    query := EncodeURL(selection)
    run, %searchURL%%query%
  }
  return


result_to_array(results, outvar)
{
  global

  stringsplit, splitresults, results, "

  numresults := (splitresults0 - 1) // 2

  pos = 2
  loop, % numresults
  {
    %outvar%%a_index% := splitresults%pos%
    pos += 2
  }
}
  

;  
;
; by shimanov, copied from AHK forum
;  
EncodeURL( p_data, p_reserved=true, p_encode=true ) 
{ 
   old_FormatInteger := A_FormatInteger 
   SetFormat, Integer, hex 

   unsafe = 
      ( Join LTrim 
         25000102030405060708090A0B0C0D0E0F101112131415161718191A1B1C1D1E1F20 
         22233C3E5B5C5D5E607B7C7D7F808182838485868788898A8B8C8D8E8F9091929394 
         95969798999A9B9C9D9E9FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6 
         B7B8B9BABBBCBDBEBFC0C1C2C3C4C5C6C7C8C9CACBCCCDCECFD0D1D2D3D4D5D6D7D8 
         D9DADBDCDDDEDF7EE0E1E2E3E4E5E6E7E8E9EAEBECEDEEEFF0F1F2F3F4F5F6F7F8F9 
         FAFBFCFDFEFF 
      ) 
       
   if ( p_reserved ) 
      unsafe = %unsafe%24262B2C2F3A3B3D3F40 
    
   if ( p_encode ) 
      loop, % StrLen( unsafe )//2 
      { 
         StringMid, token, unsafe, A_Index*2-1, 2 
         StringReplace, p_data, p_data, % Chr( "0x" token ), `%%token%, all 
      } 
   else 
      loop, % StrLen( unsafe )//2 
      { 
         StringMid, token, unsafe, A_Index*2-1, 2 
         StringReplace, p_data, p_data, `%%token%, % Chr( "0x" token ), all 
      } 
       
   SetFormat, Integer, %old_FormatInteger% 

   return, p_data
 }
 
 
 


shimanov
  • Members
  • 610 posts
  • Last active: Jul 18 2006 08:35 PM
  • Joined: 25 Sep 2005
You may want to consider an alternative method to encode the query term and submit the query:

path_browser = "C:\Program Files\Mozilla Firefox\firefox.exe"
searchURL = http://www.google.com/search?q=

queryTerm = http://www.autohotkey.com/

Run, %path_browser% "javascript:window.location.href = '%searchURL%'+escape( '%queryTerm%')"


keyboardfreak
  • Members
  • 217 posts
  • Last active: Sep 27 2010 07:21 PM
  • Joined: 09 Oct 2004
I don't plan to spend more time with this script. I made it for fun and that's it.

But feel free to post improvements here. Some may actually find the script useful and it will be useful to them.

keyboardfreak
  • Members
  • 217 posts
  • Last active: Sep 27 2010 07:21 PM
  • Joined: 09 Oct 2004
Thanks for the suggestion, BTW.

vasili111
  • Members
  • 40 posts
  • Last active: Feb 14 2016 07:25 AM
  • Joined: 08 Apr 2013

Anybody has working example?



vasili111
  • Members
  • 40 posts
  • Last active: Feb 14 2016 07:25 AM
  • Joined: 08 Apr 2013

I found information how to get google suggestions and summarize it here: http://stackoverflow...9751752/1601703