; Thesaurus
; rommmcek based on Dictionary & Thesaurus by Fanatic Guru
; 2016 01 13
; Version: 1.0.5
;
; 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
;{-----------------------------------------------
;
HP := HT := 0, History := {}, HB := 1, HM := 199 ; Maximum Word History
W := Floor(A_ScreenWidth / 2), H := Floor(A_ScreenHeight / 2)
l := 130, We := 410, Wl := W-l, Wmin := We+l+1, Hmin := 350
Style =
(
)
;Http_Data := ""
FileRead, HistoryFile, iThesaurusHistory.html
loop, parse, HistoryFile, ¥
{
if (A_LoopField = "`n") or (A_LoopField = "`r`n")
continue
HP := HT := A_Index
History[A_Index] := A_LoopField
}
; INITIALIZATION - GUI
;{-----------------------------------------------
;
Gui, Font, s14
Gui, Color, BFCDEA
Gui +LabelDictionaryGui
Gui, Margin, 1, 1
Gui, +Resize
Gui, Add, Edit, xm+5 ym w%We% h30 ; vStart gStart
Gui, Font, s12
Gui, Add, Edit, x%Wl% ym W%l% h25
Gui, Font, s14
Gui, Add, ActiveX, xm+1 w%W% h%H% vDisplay hwndHtmlControl, HTMLFile
Gui, +MinSize%Wmin%x%Hmin%
ComObjConnect(Display, "Doc_")
Gui, Show
Control, Disable,, Edit2, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
Control, Disable,, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
ControlFocus, Internet Explorer_Server1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
Gui, Hide
; goto #d
;}
goto, Search
; HOTKEYS
;{-----------------------------------------------
;
!#d:: ;<-- Dictionary Search Using Highlighted Text
Word := ""
;~ Save_Clipboard := ClipboardAll
Clipboard := ""
Sleep, 50
Send ^c
ClipWait, 0
Word := Trim(RegExReplace(Clipboard, "[0-9]"))
;~ Clipboard := Save_Clipboard
;~ Save_Clipboard := ""
if (!Word) {
Gui, Show
Display.body.innerHTML := History[HP]
}
gosub Display
Search:
if (ErrorLevel or !Word)
return
ControlFocus, Internet Explorer_Server1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
; ControlSetText, Edit1, %Word%, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
SendMessage, 0xC, 0, &Word, Edit1, iThesaurus1.0.5.ahk
if errorlevel = "FAIL"
msgbox, problem
; Control, Disable,, Edit2, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
ControlFocus, Internet Explorer_Server1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
Word:= RegExReplace(Word, "[^\w\s]")
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "http://www.thesaurus.com/browse/" Word "+?s=t", true)
; whr.Open("GET", "https://www.youtube.com/watch?v=YQHsXMglC9A", true)
whr.Send()
whr.WaitForResponse()
Http_Text := whr.ResponseText
filedelete, DictOrg.html
fileappend, % Http_Text, DictOrg.html
stringreplace, Http_Text, Http_Text, `r, , all
stringreplace, Http_Text, Http_Text, `n, `r`n, all
stringreplace, Http_Text, Http_Text, , `r`n, all
Synonyms := ""
loop, parse, Http_Text, `n
{ if instr(A_LoopField, """heading-row""") or (div > 0)
gosub block
else if instr(A_LoopField, """synonym-description""") or (div > 0)
gosub block
else if instr(A_LoopField, """relevancy-block""") or (div > 0)
gosub block
else if instr(A_LoopField, """list-holder""") or (div > 0)
gosub block
else if instr(A_LoopField, """word-origin""") or (div > 0)
{ synonyms .= "
"
gosub block
}
else if instr(A_LoopField, """example-sentences""") or (div > 0)
{ synonyms .= ""
gosub block
}
continue
block:
if instr(A_LoopField, ""
; ,"Synonyms for $1")
synonyms:= RegExReplace(synonyms, "isU)star.*")
synonyms:= RegExReplace(synonyms, "isU)") ; synonyms links
synonyms:= RegExReplace(synonyms, "isU).*Roget`'s.*Cite This Source
")
synonyms:= RegExReplace(synonyms, "isU)")
; synonyms:=RegExReplace(synonyms, "isU).*Find definition,.*games and more.*
")
} else synonyms := " No Synonyms found
"
filedelete, Dict.html
fileappend, % Synonyms, Dict.html
Display.body.innerHTML := Synonyms
History.Push(Display.body.innerHTML), HP:=++HT
FileAppend, % History[HT] "`n¥`n", iThesaurusHistory.html
If (HT >= HM)
RemovedValue := History.RemoveAt(HB), HT:=HP:=HM
Display:
Display.body.innerHTML .= Style
Display.selection.empty()
Display.parentWindow.scrollTo(0,0)
Gui, Show
ControlSetText, Edit2, % " " HP " / " HT "`t" HB " - " HM, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
; ControlSetText, Edit1, %Word%, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
; Control, Disable,, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
; ControlFocus, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
; gosub esc
return
SaveHistory:
FileDelete, iThesaurusHistory.html
loop, % HT
FileAppend, % History[A_Index] "`n¥`n", iThesaurusHistory.html
Return
#ifWinActive, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
~WheelDown::
mousegetpos,,,, E_Ctrl, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
if (E_Ctrl = "Edit1")
goto !Left
return
!Left::
~Left:: ;<-- History Back
ControlGetFocus, F_Ctrl, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
if (F_Ctrl != "Edit1") or (A_ThisHotkey = "!Left") {
if (HP = HB) {
if !getkeystate("Left","P")
KeyWait, Left
If ((A_ThisHotkey = "~Left") or (A_ThisHotkey = "!Left")) and (A_TimeSincePriorHotkey < 750)
return
}
if (HP > HB) {
Display.body.innerHTML := History[--HP]
gosub Display
}
else {
HP := HT + 1
Goto, ~Left
}
}
return
; soundPlay, C:\Program Files (x86)\Common Files\DVDVideoSoft\chimes.wav
~WheelUp::
mousegetpos,,,, E_Ctrl, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
if (E_Ctrl = "Edit1")
goto !Right
return
!Right::
~Right:: ;<-- History Forward
ControlGetFocus, F_Ctrl, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
if (F_Ctrl != "Edit1") or (A_ThisHotkey = "!Right") {
if (HP = HT) {
if !getkeystate("Right","P")
KeyWait, Right
If ((A_ThisHotkey = "~Right") or (A_ThisHotkey = "!Right")) and (A_TimeSincePriorHotkey < 750)
return
}
if (HP < HT) {
Display.body.innerHTML := History[++HP]
gosub Display
}
else {
HP := 0
goto, ~Right
}
}
return
^Del:: ;<----- Delete Current History Item
if (HP > HB) or (HP = HB) and (HT = HB) {
RemovedValue := History.RemoveAt(HP), HT--, HP--
Display.body.innerHTML := History[HP]
}
else if (HP = HB) and (HT > HB) {
RemovedValue := History.RemoveAt(HP), HT--
Display.body.innerHTML := History[HP]
}
gosub Display
gosub SaveHistory
return
!Up:: ;<----- Enlarge History Capacity
HM++
ControlSetText, Edit2, % " " HP " / " HT "`t" HB " - " HM, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
return
!Down:: ;<------- Shirk History Capacity and Delete oldest History Item if necessary
If (HM > HT)
HM--
else if (HM > HB) {
if (HP = HB)
HP++
HT:=--HM, HP--
RemovedValue := History.RemoveAt(HB)
Display.body.innerHTML := History[HP]
gosub SaveHistory
gosub, Display
}
ControlSetText, Edit2, % " " HP " / " HT "`t" HB " - " HM, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
return
;}
; SUBROUTINES - GUI
;{-----------------------------------------------
;
DictionaryGuiSize:
GuiControl, Move, %HtmlControl%, % "W" A_GuiWidth-1 "H" A_GuiHeight-1
GuiControl, Move, Edit2, % "X" A_GuiWidth-l
If ErroLevel != 1
return
return
Enter::
ControlGetText, Word, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
Control, Disable,, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
goto Search ;<------ Dictionary Search Using Text in Edit1
return
!F4:: ;<-------- Single Press: Hide Gui Interface; Double Press: Exit Application
if (A_ThisHotkey = "!F4") and (A_TimeSincePriorHotkey < 750)
ExitApp
SetTimer, HideApp, -750
return
LButton::
MouseGetPos,,,, M_Ctrl
ControlGetFocus, F_Ctrl, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
if (M_Ctrl != "Edit1") or (F_Ctrl = "Edit1")
{ click, d
KeyWait, LButton
Click, u
if (A_TimeSinceThisHotkey < 200) or (M_Ctrl != "Edit1")
Control, Disable,, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
return
}
Tab::
Esc:: ;<---- Single Press: Focus and Select Edit1 content; Double Prees: Hide Gui Interface
ControlGetFocus, F_Ctrl, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
if (F_Ctrl = "Edit1") {
Control, Disable,, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
ControlFocus, Internet Explorer_Server1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
}
else {
; if (F_Ctrl = "Intenet Explorer_Server1") {
Control, Enable,, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
ControlFocus, Edit1, iThesaurus1.0.5.ahk ahk_class AutoHotkeyGUI
SendMessage, 0xB1, 0, -1, Edit1, iThesaurus1.0.5.ahk ; ahk_class AutoHotkeyGUI ; Select
; Send, {Tab}
}
HideApp:
if (A_ThisHotkey = "Esc") and (A_TimeSincePriorHotkey < 250) or (A_ThisHotkey = "!F4")
DictionaryGuiClose:
Gui Show, Hide
return
; Make scroll possible even when Fokus on Edit1
PgDn::ControlSend, Internet Explorer_Server1, {PgDn}, iThesaurus1.0.5.ahk ; ahk_class AutoHotkeyGUI
PgUp::ControlSend, Internet Explorer_Server1, {PgUp}, iThesaurus1.0.5.ahk ; ahk_class AutoHotkeyGUI
Down::PostMessage, 0x115, 1, 0, Internet Explorer_Server1, iThesaurus1.0.5.ahk ; ahk_class AutoHotkeyGUI
Up::PostMessage, 0x115, 0, 0, Internet Explorer_Server1, iThesaurus1.0.5.ahk ; ahk_class AutoHotkeyGUI
;}
; 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
;~ }
;~ 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
;~ }
;~ ;}
;~ 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 !#d
}
;}