Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

Post your working scripts, libraries and tools
fenchai
Posts: 224
Joined: 28 Mar 2016, 07:57

Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

14 Jan 2018, 11:30

Brief Intro:
I use this on my daily work, Using this to do searches on my inventory program but I still sometimes use it for google searching, youtube, Amazon, eBay, etc. But more often to do my personal inventory searches.
I thought this was a cool idea more people need to learn about. I was inspired and helped by many others, most I can do is share.

Image

This is not the first program that can do this type of custom search but one I do know how to control and customize easily. You can change the background color, letter, size etc by themes. Google, Amazon, Ebay etc.

How to Use:
Just need to type Prefix_Search. For Example: "g AHK Search testing" Searches for AHK Search testing on Google

Code:

Code: Select all

	;ToolTip for LAtl & Space
	ToolTipCommands =
		( LTrim
		Please Reload to Close. Not Sure why ESC not Working
		You can Still Drag Though :D
		***********WEB SEARCHES**********
		1)g_ Google Search
		2)i_ Google Image Search
		3)x_ Google Incognito Search
		4)y_ Youtube Search
		5)a_ Amazon Search
		6)e_ Ebay Search
		******GOOGLE TRANSLATIONS*****
		1)kor_ korean
		2)eng_ English
		3)spa_ Spanish
		4)chi_ Chinise
		)

; Universal Searcher  ========

	#If WinActive(universal_window)

	Down::Send, {Tab}  ;move down
	
	Up::Send, +{Tab}  ;move up

	Enter:: ;Gosub Buscar
	NumpadEnter:: ;Gosub Buscar
		gosub, Buscar
		return
	
	Esc::
		ToolTip
		Gui, Universal_Searcher: Destroy
		return
	
	^BackSpace::Send, ^a{Del} ;Send Delete ALL to del_win group Windows
	
	; Universal Searcher PROJECT========

	main_theme:
		Description_text					      = Searching Inventory: `n"%Search%" ;if no match
		Background_color                  	  = 00A03E ;C7C7C9
		Editbox_color                         	  = EDEDED
		Editbox_font_size         	          = s16
		Editbox_font_color                    = cblack
		Editbox_font			                  = Lucida Sans 
		Description_font_size			      = s11 
		Description_font_color			  = +cWhite  ;I have no idea what the + sign does but it works ¯\_(ツ)_/¯ 
		Description_font                  	  = Lucida Console 
		return
	
	google_theme:
		Description_text					      = Searching Google: `n"%Search%" ;if no match
		Background_color                  	  = 0078D7
		Editbox_color                         	  = EDEDED
		Description_font_color              = +cwhite
		return

	google_images_theme:
		Description_text                        = Searching Google Images: `n"%newmatch%"
		Background_color                     = 0078D7 
		Editbox_color                            = EDEDED
		Description_font_color              = +cwhite
		return

	youtube_theme:
		Description_text                       = Searching YouTube: `n"%newmatch%"
		Background_color                 	 = FF5454 
		Editbox_color                           = EDEDED
		Description_font_color             = +cwhite		
		return

	SendAnywhere_theme:
		Description_text                       = Send Anywhere: `n"%newmatch%" enter 6-digit code.
		Background_color                 	 = F16F5F 
		Editbox_color                           = EDEDED
		Description_font_color             = +cwhite	
		return

	Amazon_theme:
		Description_text                       = Searching Amazon for: `n"%newmatch%"
		Background_color                 	 = F4AE01 
		Editbox_color                           = EDEDED
		Description_font_color             = +cwhite		
		return

	Ebay_theme:
		Description_text                       = Searching Ebay for: `n"%newmatch%"
		Background_color                 	 = F4AE01 
		Editbox_color                           = EDEDED
		Description_font_color             = +cwhite		
		return

	Translator_theme:
		Description_text                       = Translating: `n"%newmatch%"
		Background_color                 	 = F16F5F 
		Editbox_color                           = EDEDED
		Description_font_color             = +cwhite		
		return

	Clients_Search_theme:
		Description_text                       = Searching Customer: `n"%newmatch%"
		Background_color                 	 = 4CFF4C 
		Editbox_color                           = EDEDED
		Description_font_color             = +cblack		
		return

	#If
	
	LAlt & Space:: ;Open Buscador Universal
		universal_window=Universal Searcher
	IfWinExist, %universal_window%
	{
		WinActivate, %universal_window%
		return
	} else {
		gosub, main_theme
		Gui, Universal_Searcher: Cancel ;just in case it's still active, close it
		IniRead, L_Search, %A_ScriptDir%\info.ini,Script_Properties,lastSearch ;reads latest search
		; Gui Settings 
		Gui, Universal_Searcher: +AlwaysOnTop +ToolWindow -caption +LastFound +border ;sysmenu = min,max,close and icon ;+Border ;caption = the border and titlebar ; toolwindow = taskbar button & alt-tab; 
		Gui, Universal_Searcher: Color, %Background_color%  , %Editbox_color%   ;first one is for gui background, second is for the Gui editbox
		; Gui Buttons, Pics, Texts 
			Gui, Universal_Searcher: font, %Editbox_font_size% %EditBox_font_color%, %Editbox_font% ;color and font for Edit Box
		Gui, Universal_Searcher: Add, Edit, xp+0 yp+10 w380 vSearch gOnChangeMyText , %L_Search% ;Edit Box ;add xm w220 -E0x200 r1 to remove editbox borders but edit text looks weird
			Gui, Universal_Searcher: font, %Description_font_size% %Description_font_color%, %Description_font% ;color and font for Description Text 
		Gui, Universal_Searcher: Add, Text, xp+5 yp+35 w375 r3 vhelpinghand, Inventory Searching for: `n"%Search%" ;Description
		
		Gui, Universal_Searcher: Show, AutoSize, %universal_window%  ;Show GUI
		
		OnMessage( 0x200, "WM_MOUSEMOVE" ) ;let's mouse drag GUI 

	} return


	WM_MOUSEMOVE( wparam, lparam, msg, hwnd )
	{
		if wparam = 1 ; LButton
			PostMessage, 0xA1, 2,,, A ; WM_NCLBUTTONDOWN
	}

	Submit: ;subroutine for Submiting text from editbox (When you press Enter)
		Gui, Universal_Searcher: Submit
		IniWrite, %Search%, %A_ScriptDir%\info.ini,Script_Properties,lastSearch ;writes latest search
		Clipboard = 
		Clipboard := Search
		ClipWait
		return
	
	Changes:
		GuiControl, Text, helpinghand, %Description_text%
		Gui, Universal_Searcher: Color, %Background_color% ,%Editbox_color% ;first one is for gui background, second is for the Gui editbox
		GuiControl, %Description_font_color%, helpinghand
		return

	RegexFormula:
		RegExMatch(Search, "i)^([abcdefghiklmnopqrstvxyz]|kor|eng|spa|chi) (.*)", m) ;separates "Search" into 2 parts
		type := m1	;type of the search... y,g,i,e,a...etc (part1)
		newmatch := m2 ;stores the modified search (part2)
		return

	OnChangeMyText:

	Gui, Universal_Searcher: Submit, NoHide ; Get the info entered in the GUI without force closing window
	gosub, RegexFormula

		If (type = "g"){
			gosub, google_theme
			gosub, Changes
		} else If (type = "i"){
			gosub, google_images_theme
			gosub, Changes
		} else If (type = "y"){
			gosub, youtube_theme
			gosub, Changes
		} else If (type = "a"){
			gosub, Amazon_theme
			gosub, Changes
		} else If (type = "e"){
			gosub, Ebay_theme
			gosub, Changes
		} else If (type = "kor"){
			gosub, Translator_theme
			gosub, Changes
		} else If (type = "eng"){
			gosub, Translator_theme
			gosub, Changes
		} else If (type = "spa"){
			Description_text = Translating... `n"%newmatch%" into SPANISH.
			gosub, Translator_theme
			gosub, Changes
		} else If (type = "chi"){
			gosub, Translator_theme
			gosub, Changes
		} else If (type = "c"){
			gosub, Clients_Search_theme
			gosub, Changes
		} else {
			gosub, main_theme
			gosub, Changes
		} return
	

	Buscar: ;MAIN SEARCH PROCESS
		ToolTip
		gosub, Submit
		Gui, Universal_Searcher: Destroy
		gosub, RegexFormula
		
		If (type = "g"){
			Run, "https://www.google.com/search?num=50&safe=off&site=&source=hp&q=%newmatch%&btnG=Search&oq=&gs_l="
		} else If (type = "i"){
			Run, "http://www.google.com/search?q=%newmatch%&um=1&ie=UTF-8&tbm=isch&source=og&sa=N&hl=en&tab=wi&biw=1920&bih=1075"
		} else If (type = "x"){
			Run, "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe -incognito https://www.google.com/search?safe=off&q=%newmatch%"
		} else If (type = "y"){
			Run, "https://www.youtube.com/results?search_query=%newmatch%"
		} else If (type = "a"){
			Run, "www.amazon.com/s/ref=nb_sb_noss?url=search-alias`%3Daps&field-keywords=%newmatch%"
		} else If (type = "e"){
			Run, "www.ebay.com/sch/%newmatch%"
		} else If (type = "kor"){
			Run, "https://translate.google.com/#auto/ko/%newmatch%"
		} else If (type = "eng"){
			Run, "https://translate.google.com/#auto/en/%newmatch%"
		} else If (type = "spa"){
			Run, "https://translate.google.com/#auto/es/%newmatch%"
		} else If (type = "chi"){
			Run, "https://translate.google.com/#auto/zh-CN/%newmatch%"
		} else {
			MsgBox, You Should Try other Prefixes.
			ToolTip, %ToolTipCommands% ;Help menu Tootip
		}
		return
Finally:

Please tell me how you would add any other code or fix to make this better as I am still a beginner.
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

14 Jan 2018, 15:24

Very nice ! for my use i will make some changes ( if you do not mind :) ).Using the prefixes is quite good but i will do with less options and also for the translate i prefer not to open a browser window but have the translation direct in a tooltip or GUI using google api.
I will take a closer look at your code ,i will change the window style to fit the overal theme i use.Thanks for sharing fenchai.

Greetings,
soundcloud.com/user-32706894
fenchai
Posts: 224
Joined: 28 Mar 2016, 07:57

Re: Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

14 Jan 2018, 18:30

noname wrote:Very nice ! for my use i will make some changes ( if you do not mind :) ).Using the prefixes is quite good but i will do with less options and also for the translate i prefer not to open a browser window but have the translation direct in a tooltip or GUI using google api.
I will take a closer look at your code ,i will change the window style to fit the overal theme i use.Thanks for sharing fenchai.

Greetings,
Please do share :) I want to see how you can improve the code. There are some additions I was never able to do since I do not know how to or have the experience.

* A way to Type and it lets me see a list of 3-5 items below the edit box just like how when you type on Google it finds the most common searches. (Our case would come from a .csv file with a list of "items", I need this for my inventory search that way I do not need to remember so many numbers. But if we could get Google API searches, that would be even more awesome!)

*There is also a pesky bug I do not know how to fix. Happens randomly but when it happens, I need to reload the script to fix. I think it has to do with the method I use for the hotkey to show the GUI. (image below shows extra code in gui for my work pc, sorry if confusing.)

Image

* I wanted to delete the prefix on the description but never had the time to do it but since it was not that important, I just left it there :D

* I tried to find a way to theme it as beautifully as possible but This is the most I can do with my knowledge of GUIs. Try to beat me :)
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

15 Jan 2018, 06:31

Image

Here is the translator code i use, i do not know where i got the code snippets from ( maybe RUNIE ? ) there are several on the forum.

Code: Select all

#numpadadd::
if strlen(clipboard)<100
MsgBox,,translate, % clipboard "`n"GoogleTranslate(clipboard)
return


GoogleTranslate(str, from := "auto", to := "en")  {
   static JS := GetJScripObject(), _ := JS.( GetJScript() ) := JS.("delete ActiveXObject; delete GetObject;")
   
   json := SendRequest(JS, str, to, from, proxy := "")
   oJSON := JS.("(" . json . ")")

   if !IsObject(oJSON[1])  {
      Loop % oJSON[0].length
         trans .= oJSON[0][A_Index - 1][0]
   }
   else  {
      MainTransText := oJSON[0][0][0]
      Loop % oJSON[1].length  {
         trans .= "`n+"
         obj := oJSON[1][A_Index-1][1]
         Loop % obj.length  {
            txt := obj[A_Index - 1]
            trans .= (MainTransText = txt ? "" : "`n" txt)
         }
      }
   }
   if !IsObject(oJSON[1])
      MainTransText := trans := Trim(trans, ",+`n ")
   else
      trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")

   from := oJSON[2]
   trans := Trim(trans, ",+`n ")
   Return trans
}

SendRequest(JS, str, tl, sl, proxy) {
   ComObjError(false)
   http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   ( proxy && http.SetProxy(2, proxy) )
   http.open( "POST", "https://translate.google.com/translate_a/single?client=t&sl="
      . sl . "&tl=" . tl . "&hl=" . tl
      . "&dt=at&dt=bd&dt=ex&dt=ld&dt=md&dt=qca&dt=rw&dt=rm&dt=ss&dt=t&ie=UTF-8&oe=UTF-8&otf=1&ssel=3&tsel=3&pc=1&kc=2"
      . "&tk=" . JS.("tk").(str), 1 )

   http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
   http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
   http.send("q=" . URIEncode(str))
   http.WaitForResponse(-1)
   Return http.responsetext
}

URIEncode(str, encoding := "UTF-8")  {
   VarSetCapacity(var, StrPut(str, encoding))
   StrPut(str, &var, encoding)

   While code := NumGet(Var, A_Index - 1, "UChar")  {
      bool := (code > 0x7F || code < 0x30 || code = 0x3D)
      UrlStr .= bool ? "%" . Format("{:02X}", code) : Chr(code)
   }
   Return UrlStr
}

GetJScript()
{
   script =
   (
      var TKK = ((function() {
        var a = 561666268;
        var b = 1526272306;
        return 406398 + '.' + (a + b);
      })());

      function b(a, b) {
        for (var d = 0; d < b.length - 2; d += 3) {
            var c = b.charAt(d + 2),
                c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c),
                c = "+" == b.charAt(d + 1) ? a >>> c : a << c;
            a = "+" == b.charAt(d) ? a + c & 4294967295 : a ^ c
        }
        return a
      }

      function tk(a) {
          for (var e = TKK.split("."), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) {
              var c = a.charCodeAt(f);
              128 > c ? g[d++] = c : (2048 > c ? g[d++] = c >> 6 | 192 : (55296 == (c & 64512) && f + 1 < a.length && 56320 == (a.charCodeAt(f + 1) & 64512) ?
              (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240,
              g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128)
          }
          a = h;
          for (d = 0; d < g.length; d++) a += g[d], a = b(a, "+-a^+6");
          a = b(a, "+-3^+b+-f");
          a ^= Number(e[1]) || 0;
          0 > a && (a = (a & 2147483647) + 2147483648);
          a `%= 1E6;
          return a.toString() + "." + (a ^ h)
      }
   )
   Return script
}

GetJScripObject()  {
   VarSetCapacity(tmpFile, (MAX_PATH := 260) << !!A_IsUnicode, 0)
   DllCall("GetTempFileName", Str, A_Temp, Str, "AHK", UInt, 0, Str, tmpFile)
   
   FileAppend,
   (
   <component>
   <public><method name='eval'/></public>
   <script language='JScript'></script>
   </component>
   ), % tmpFile
   
   JS := ObjBindMethod( ComObjGet("script:" . tmpFile), "eval" )
   FileDelete, % tmpFile
   Return JS
}
You can find solutions on the forum for a list of suggestions when typing.Luckily you kept the prefix !It is something i am sure to use :)
soundcloud.com/user-32706894
fenchai
Posts: 224
Joined: 28 Mar 2016, 07:57

Re: Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

15 Jan 2018, 11:48

I see, I will try asking in the community.

Thanks for the translation code. Hopefully it works for long texts lol.
burque505
Posts: 1069
Joined: 22 Jan 2017, 19:37

Re: Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

21 May 2018, 15:01

Hi fenchai, thanks for this.
The script as written never hits the 'Escape::' routine because of '#If WinActive(universal_window)', I think. Anyway, I cut the whole routine and added this at the very end (you can also use 'return' - a second 'return' after the 'return' in the 'Buscar:' label, that is - instead of #IfWinActive, I'm pretty sure:

Code: Select all

#IfWinActive

	Esc::
		ToolTip
		Gui, Universal_Searcher: Destroy
		Return
Regards,
burque505
burque505
Posts: 1069
Joined: 22 Jan 2017, 19:37

Re: Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

21 May 2018, 15:11

:headwall: Managed a double post. Sorry.
Maybe I fixed the bug described above - I experienced it too.
Please test:
Spoiler
Thanks!
burque505
fenchai
Posts: 224
Joined: 28 Mar 2016, 07:57

Re: Universal_Searcher - use Prefixes to do custom searches On YouTube, Google, Amazon, local files etc

22 May 2018, 16:21

burque505 wrote::headwall: Managed a double post. Sorry.
Maybe I fixed the bug described above - I experienced it too.
Please test:
Spoiler
Thanks!
burque505
Thanks for this :) I'm glad this post still has some attention. I think I have a lot of changes since then but I haven't had the time to update the post. I'm glad you found the bug :D its quite silly.

Return to “Scripts and Functions”

Who is online

Users browsing this forum: No registered users and 36 guests