Preforms a google search of highlighted text or text input if no text is highlighted using the default browser.
Code: Select all
; Google
; Fanatic Guru
; 2016 03 15
; Version: 1.21
;
; Google Search of Highlighted Text
;
;{-----------------------------------------------
; If Internet Explorer is already running it will add search as new tab
;}
; INITIALIZATION - ENVIROMENT
;{-----------------------------------------------
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force ; Ensures that only the last executed instance of script is running
;}
; AUTO-EXECUTE
;{-----------------------------------------------
;
RegRead, ProgID, HKEY_CURRENT_USER, Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice, Progid
Browser := "iexplore.exe"
if (ProgID = "ChromeHTML")
Browser := "chrome.exe"
if (ProgID = "FirefoxURL")
Browser := "firefox.exe"
if (ProgID = "AppXq0fevzme2pys62n3e0fbqa7peapykr8v")
Browser := "microsoft-edge:"
;
;}-----------------------------------------------
; END OF AUTO-EXECUTE
; HOTKEYS
;{-----------------------------------------------
;
#g:: ; <-- Google Web Search Using Highlighted Text
Search := 1
Gosub Google
return
^#g:: ; <-- Google Image Search Using Highlighted Text
Search := 2
Gosub Google
return
!#g:: ; <-- Google Map Search Using Highlighted Text
Search := 3
Gosub Google
return
;}
; SUBROUTINES
;{-----------------------------------------------
;
Google:
Save_Clipboard := ClipboardAll
Clipboard := ""
Send ^c
ClipWait, .5
if !ErrorLevel
Query := Clipboard
else
InputBox, Query, Google Search, , , 200, 100, , , , , %Query%
StringReplace, Query, Query, `r`n, %A_Space%, All
StringReplace, Query, Query, %A_Space%, `%20, All
StringReplace, Query, Query, #, `%23, All
Query := Trim(Query)
if (Search = 1)
Address := "http://www.google.com/search?hl=en&q=" Query ; Web Search
else if (Search = 2)
Address := "http://www.google.com/search?site=imghp&tbm=isch&q=" Query ; Image Search
else
Address := "http://www.google.com/maps/search/" Query ; Map Search
if (Browser = "iexplore.exe")
{
Found_IE := false
For wb in ComObjCreate("Shell.Application").Windows
If InStr(wb.FullName, "iexplore.exe")
{
Found_IE := true
break
}
if Found_IE
wb.Navigate(Address, 2048)
else
{
wb := ComObjCreate("InternetExplorer.Application")
wb.Visible := true
wb.Navigate(Address)
}
WinHwnd := wb.HWND
WinActivate ahk_id %WinHwnd%
}
else
Run, %browser% %Address%
Clipboard := Save_Clipboard
Save_Clipboard := ""
return
;}
Preforms a dictionary search at Dictionary.com of the highlighted text or text input if no text is highlighted. The results are trimmed down and displayed in a Gui using an ActiveX control.
- When Gui is active, can double click on word in Gui to then search for that word.
- When Gui is active, can use Left and Right arrows to move back and forth through history.
Code: Select all
; Dictionary
; Fanatic Guru
; 2016 03 10
; Version: 1.21
;
; Dictionary Search at Dictionary.com
;
;{-----------------------------------------------
; Downloads http text from website and trim it down and format for display in ActiveX Gui
;}
; INITIALIZATION - ENVIROMENT
;{-----------------------------------------------
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force ; Ensures that only the last executed instance of script is running
SetControlDelay -1
;}
; INITIALIZATION - VARIABLES
;{-----------------------------------------------
;
History := {}
HP := 0
HB := 1
HM := 15 ; Maximum Word History
W := Floor(A_ScreenWidth / 3)
H := Floor(A_ScreenHeight / 3)
;}
; INITIALIZATION - GUI
;{-----------------------------------------------
;
Gui +LabelDictionaryGui
Gui, Margin, 0, 0
Gui, +Resize
Gui, Add, ActiveX, w%W% h%H% vDisplay hwndHtmlControl, HTMLFile
ComObjConnect(Display, "Doc_")
;}
; HOTKEYS
;{-----------------------------------------------
;
#d:: ;<-- Dictionary Search Using Highlighted Text
Hotkey_Start:
Word := ""
Save_Clipboard := ClipboardAll
Clipboard := ""
Send ^c
ClipWait, .5
Word := Clipboard
Clipboard := Save_Clipboard
Save_Clipboard := ""
if !Word
{
InputBox Word, Define Word, Enter word to define., , 200, 120
if (ErrorLevel or !Word)
return
}
HT := ++HP
If (HT - HB > HM)
History[HB] := "", HB ++
Display.body.innerHTML := Get_Definition_Html(RegExReplace(Word, "[^\w\s]"))
RemoveNodeByClassName(Display
, "ipapron"
, "headword-bar-list"
, "pronounce-button"
, "syllable-button"
, "button-source"
, "tail-wrapper"
, "video-content"
, "audio-wrapper"
, "deep-link-synonyms")
History[HP] := Display.body.innerHTML
Display:
Display.selection.empty()
Display.parentWindow.scrollTo(0,0)
Gui, Show
return
#ifWinActive, Dictionary.ahk ahk_class AutoHotkeyGUI
Left:: ;<-- History Back
if (HP > HB)
{
Display.body.innerHTML := History[--HP]
gosub Display
}
return
Right:: ;<-- History Forward
if (HP < HT)
{
Display.body.innerHTML := History[++HP]
gosub Display
}
return
;}
; SUBROUTINES - GUI
;{-----------------------------------------------
;
DictionaryGuiSize:
GuiControl, Move, %HtmlControl%, W%A_GuiWidth% H%A_GuiHeight%
return
DictionaryGuiClose:
DictionaryGuiEscape:
Gui Show, Hide
HP := HT
return
;}
; FUNCTIONS
;{-----------------------------------------------
;
Get_Definition_Html(Word)
{
if !whr
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "http://dictionary.reference.com/browse/" Word "+?s=t", true)
whr.Send()
whr.WaitForResponse()
Http_Text := whr.ResponseText
if RegExMatch(Http_Text, "sU)Did you mean <a href=.*<span class=""me"" .*>(.*)</span>",Match)
return "<font size=""4em"">Did you mean </font><font size=""6em""><b>" Match1 "</b>?</font>"
if RegExMatch(Http_Text,"sU)(<div class=""center-well-container"".*)<div class=""source-meta"">", Section)
Section := Section1
else
return "<h1>" Word "</h1><h2>NO results found on Dictionary.com</h2>"
Section := RegExReplace(Section, "\(<span class=""prontoggle pronounce-inline"">Show IPA</span>\)")
Section := RegExReplace(Section, "sU)<a [^>]*href=[^>]*>(.*)</a>","$1")
Section := RegExReplace(Section, "sU)<header class=""luna-data-header"">(.*)</header>","<h3 style=""margin-top: .5em; margin-bottom: 0em; text-decoration: underline;"">$1</h3>")
Section := RegExReplace(Section, "sU)<div class=""def-block def-inline-example"">(.*)</div>","$1")
Section =
(
%Section%
<style>
.head-entry {margin-bottom: 0em; font-size: 2em;}
.dbox-example {color:gray;}
.dbox-italic {font-style:italic;}
.dbox-bold {font-weight:bold;}
.def-sub-list {margin: -.1em 0em .5em 2em; list-style-type: lower-alpha}
.def-content {margin: -1.1em 0em 0em 2em;}
.def-block-label-synonyms {margin-left: 1em;}
</style>
)
return Section
}
RemoveNodeByClassName(ByRef Doc, Names*)
{
for index, Name in Names
Needle .= Name "|"
Needle := "i)\b" SubStr(Needle,1,-1) "\b"
list := Doc.getElementsByTagName("*")
Count := list.length
loop %Count%
if (child := list[Count-A_Index])
if (child.className ~= Needle)
child.parentNode.removeChild(child)
return
}
;}
; FUNCTIONS - GUI
;{-----------------------------------------------
;
Doc_OnKeyPress(Doc)
{
static keys := {1:"selectall", 3:"copy", 22:"paste", 24:"cut"}
keyCode := Doc.parentWindow.event.keyCode
If keys.HasKey(keyCode)
Doc.ExecCommand(keys[keyCode])
}
Doc_OnDblClick()
{
gosub Hotkey_Start
}
;}
Preforms a thesaurus search at Thesaurus.com of the highlighted text or text input if no text is highlighted. The results are trimmed down and displayed in a Gui using an ActiveX control.
- When Gui is active, can double click on word in Gui to then search for that word.
- When Gui is active, can use Left and Right arrows to move back and forth through history.
- When Gui is active, can use Tab to move to box at top to enter new word.
Code: Select all
; Thesaurus
; Fanatic Guru
; 2016 03 15
; Version: 1.0
;
; Thesaurus Search at Thesaurus.com
;
;{-----------------------------------------------
; Downloads http text from website and trim it down and format for display in ActiveX Gui
;}
; INITIALIZATION - ENVIROMENT
;{-----------------------------------------------
;
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
#SingleInstance force ; Ensures that only the last executed instance of script is running
SetControlDelay -1
;}
; INITIALIZATION - VARIABLES
;{-----------------------------------------------
;
History := {}
HP := 0
HB := 1
HM := 15 ; Maximum Word History
W := 700
H := 400
Style =
(
<style>
ul {
padding: 1em;
margin: -1em 0em 0em 2em;
float: left;
}
.heading-row {
clear: left;
}
H2 {
margin: .1em 0em .1em 0em;
}
.header-antonyms {
margin: -.3em 0em 0em 0em;
font-size: 1.25em;
}
.synonym-description {
border-top: 1px solid black;
border-bottom: 1px solid black;
}
.synonyms-horizontal-divider {
position: relative;
top: -3.1em;
border-top: 1px solid black;
border-bottom: 2px solid black;
}
</style>
)
;}
; INITIALIZATION - GUI
;{-----------------------------------------------
;
Gui +LabelThesaurusGui
Gui, Margin, 0, 0
Gui, +Resize +MinSize700x400
Gui, Font, s18 Bold, Verdana
Gui, Add, Edit, 0x8 0x1 -VScroll r2 x0 y0 w%W% vBanner gBanner_Enter hwndBannerControl
GuiControl, Move, Banner, h38
Gui, Add, ActiveX, x0 y38 w%W% h%H% vDisplay hwndHtmlControl, HTMLFile
ComObjConnect(Display, "Doc_")
oHTML := ComObjCreate("HTMLfile")
oHTML.write("<div>Initilize</div>")
;}
; HOTKEYS
;{-----------------------------------------------
;
#!d:: ;<-- Thesaurus Search Using Highlighted Text
Hotkey_Start:
Save_Clipboard := ClipboardAll
Clipboard := ""
Send ^c
ClipWait, .5
Word := Clipboard
Clipboard := Save_Clipboard
Save_Clipboard := ""
Display.body.innerHTML := ""
Banner_Input:
if Word
{
Word := RegExReplace(Word, "[^\w\s]")
HT := ++HP
If (HT - HB > HM)
History[HB] := "", HB ++
oHTML.body.innerHTML := Get_Html("http://thesaurus.com/browse/" Word)
oHTML.body.innerHTML := GetNodesByClassName(oHTML,"synonyms_wrapper")[1].outerHTML Style
StripElements(oHTML, "A")
RemoveNodesByClassName(oHTML
, "citation"
, "star inactive"
, "tabset"
, "form-block"
, "synonyms-heading"
, "misspell-bottom")
oHTML.body.innerHTML := RegExReplace(RegExReplace(oHTML.body.innerHTML,"U)<H2>Antonyms.*</H2>", "<H2 class=header-antonyms>Antonyms</H2>"), "U)<H2>Synonyms.*</H2>", "<H2>Synonyms</H2>")
Display.body.innerHTML := oHTML.body.innerHTML
History[HP,"Body"] := Display.body.innerHTML
History[HP,"Word"] := Word
}
Display:
GuiControl,, Banner, %Word%
if Word
GuiControl, Focus, Display
else
GuiControl, Focus, Banner
Display.selection.empty()
Display.parentWindow.scrollTo(0,0)
Gui, Show
return
#ifWinActive, Thesaurus.ahk ahk_class AutoHotkeyGUI
Left:: ;<-- History Back
if (HP > HB)
{
--HP
Display.body.innerHTML := History[HP,"Body"]
Word := History[HP,"Word"]
gosub Display
}
return
Right:: ;<-- History Forward
if (HP < HT)
{
++HP
Display.body.innerHTML := History[HP,"Body"]
Word := History[HP,"Word"]
gosub Display
}
return
;}
; SUBROUTINES - GUI
;{-----------------------------------------------
;
ThesaurusGuiSize:
GuiControl, Move, %HtmlControl%, % "W" A_GuiWidth " H" A_GuiHeight-36
GuiControl, Move, %BannerControl%, % "W" A_GuiWidth
return
ThesaurusGuiClose:
ThesaurusGuiEscape:
Gui Show, Hide
HP := HT
return
Banner_Enter:
Gui, Submit, NoHide
if Banner contains `n
{
Word := Trim(Banner, " `t`n")
gosub Banner_Input
}
return
;}
; FUNCTIONS
;{-----------------------------------------------
;
Get_HTML(Http)
{
if !whr
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", Http, true)
whr.Send()
whr.WaitForResponse()
return whr.ResponseText
}
GetNodesByClassName(ByRef Doc, Names*)
{
Nodes := {}
for index, Name in Names
Needle .= Name "|"
Needle := "i)\b" SubStr(Needle,1,-1) "\b"
list := Doc.getElementsByTagName("*")
Count := list.length
loop %Count%
if (child := list[A_Index-1])
if (child.className ~= Needle)
Nodes.Push(child)
return Nodes
}
RemoveNodesByClassName(ByRef Doc, Names*)
{
for index, Name in Names
Needle .= Name "|"
Needle := "i)\b" SubStr(Needle,1,-1) "\b"
list := Doc.getElementsByTagName("*")
Count := list.length
loop %Count%
if (child := list[Count-A_Index])
if (child.className ~= Needle)
child.parentNode.removeChild(child)
return
}
StripElements(ByRef Doc, Elements*)
{
for index, Element in Elements
{
list := Doc.getElementsByTagName(Element)
Count := list.length
loop %Count%
list[Count-A_Index].outerHTML := list[Count-A_Index].innerHTML
}
return Count
}
;}
; FUNCTIONS - GUI
;{-----------------------------------------------
;
Doc_OnKeyPress(Doc)
{
static keys := {1:"selectall", 3:"copy", 22:"paste", 24:"cut"}
keyCode := Doc.parentWindow.event.keyCode
If keys.HasKey(keyCode)
Doc.ExecCommand(keys[keyCode])
}
Doc_OnDblClick()
{
gosub Hotkey_Start
}
;}