Guest User

Untitled

a guest
Apr 22nd, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;#NoTrayIcon
  2. #Persistent
  3. #SingleInstance
  4.  
  5. KeySequence := "^!s"
  6.  
  7. ; chrome site local search
  8. ;
  9. ; usage:
  10. ;
  11. ;   viewing some site,
  12. ;     with chrome focused,
  13. ;     input hotkey --
  14. ;     default is ctrl+alt+s
  15. ;
  16. ;   at dialog,
  17. ;     enter query term,
  18. ;     then press enter,
  19. ;     or click ok
  20. ;
  21. ;   confirm address field,
  22. ;     press enter and
  23. ;     wait for results...
  24. ;     now it's time for manual scanning :)
  25. ;  
  26.  
  27. SiteLocalSearch()
  28. {
  29.   ; XXX: test more?
  30.   ;ControlFocus, Chrome_OmniboxView1, A
  31.   ;If (ErrorLevel != 0)
  32.   ;{
  33.   ;  OutputDebug, % "ControlFocus failed for Chrome_OmniboxView1"
  34.   ;  SoundBeep
  35.   ;  Return
  36.   ;}
  37.   ; XXX: hack to focus location field
  38.   Send ^l
  39.   ClipSaved := ClipboardAll
  40.   Clipboard := ""
  41.   ; XXX: hack to obtain content of location field
  42.   Send ^c
  43.   ClipWait
  44.   Captured := Clipboard
  45.   Clipboard := ClipSaved
  46.   OutputDebug, % "Captured: " . Captured
  47.   ;
  48.   Pattern := "iO)^(https?://([^/]+))"
  49.   FoundPos := RegExMatch(Captured, Pattern, MObj)
  50.   If (ErrorLevel != 0)
  51.   {
  52.     OutputDebug, % "RegExMatch ErrorLevel: " . ErrorLevel
  53.     SoundBeep
  54.     Return
  55.   }
  56.   If (FoundPos == 0)
  57.   {
  58.     OutputDebug, % "RegExMatch did not parse: " . Captured
  59.     SoundBeep
  60.     Return
  61.   }
  62.   Prefix := MObj[1]
  63.   OutputDebug, % "Matched: " . Prefix
  64.   ;
  65.   InputBox, QueryStr, % "Site Local Search", % "Search within: " . Prefix
  66.           , , , 130
  67.   If (ErrorLevel != 0)
  68.   {    
  69.     OutputDebug, % "InputBox ErrorLevel: " . ErrorLevel
  70.     Return
  71.   }
  72.   ClipSaved := ClipboardAll
  73.   PasteStr := "site:" . Prefix . " " . QueryStr
  74.   OutputDebug, % "About to paste: " . PasteStr
  75.   ;
  76.   Clipboard := PasteStr
  77.   ; XXX: hack to edit location field
  78.   Send ^v
  79.   Clipboard := ClipSaved
  80.   Return
  81. }
  82.  
  83. #If WinActive("ahk_class Chrome_WidgetWin_0")
  84. Hotkey, % KeySequence, DoSiteLocalSearch
  85.  
  86. Return
  87.  
  88. DoSiteLocalSearch:
  89. {
  90.   SiteLocalSearch()
  91.   Return
  92. }
Add Comment
Please, Sign In to add comment