Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; Autoexecute
- #NoEnv
- #SingleInstance force
- Process, priority, , High
- SetMouseDelay, -1
- SetBatchLines, -1
- SetControlDelay, -1
- SetKeyDelay, -1
- SetWinDelay, -1
- Gui Result:Color, F0F0F0
- Gui Result:Font, s10 bold, Verdana
- Gui Result:Add, Text, w800 r1 vWrd
- Gui Result:Font, norm
- Gui Result:Add, Edit, w800 r30 vDef t15 +ReadOnly -Wrap HScroll
- ;//COPYING WORDS TO REMEMBER IN TEXT FILE//
- FileName := "C:\Program Files\AutoHotkey\newwords.txt"
- !`::Run Edit "C:\Program Files\AutoHotkey\newwords.txt"
- return
- ^`::
- FileAppend, % get_Highlight() "`n", %FileName%
- ;-------------------------------------------------------------------------------
- get_Highlight() { ; get highlighted text
- ;-------------------------------------------------------------------------------
- ClipStore := Clipboard ; store current content
- Clipboard = ; empty
- SendInput, ^c ; copy highlighted text
- ClipWait ; wait for change
- Result := Clipboard ; store highlighted text
- Clipboard := ClipStore ; restore clipboard's previous content
- Return, Result
- }
- return
- ;//
- +`::
- InputBox Word, Define Word, Enter word to define., , 150, 120
- if (ErrorLevel)
- return
- Word := RegExReplace(Word, "[^\w\s]")
- StringLower Word, Word
- gosub FindDef
- return
- `::
- Send {LButton}
- Send {LButton}
- SaveClip := ClipboardAll
- Clipboard := ""
- Send ^c
- ClipWait 1
- Word := RegExReplace(Clipboard, "[^\w\s]")
- Clipboard := SaveClip
- SaveClip := ""
- if (Word) {
- StringLower Word, Word
- gosub FindDef
- }
- return
- ;^R:: Reload
- FindDef:
- if !Html := UrlGet("https://www.dictionary.com/browse/" Word "?s=t") {
- MsgBox No data returned from Dictionary.com
- return
- }
- Loop Parse, Html, `n, `r
- {
- ; if SubStr(A_LoopField, 8, 46) <> "<!-- Google Analytics GTM iframe ends here -->"
- if InStr(A_LoopField, "<div id=""root""><div data-reactroot="""">") == 0
- continue
- ; Variations - different forms of word entered
- ; Type - noun, verb, adjective, etc.
- ;RegExMatch(A_LoopField, "([^>]+)(?=</h2>)", Variation)
- Result := ""
- Pos=1
- While Pos := RegExMatch(A_LoopField, "<div value=.+?>.+?</div>", match ,Pos+StrLen(match))
- {
- example := ""
- RegExMatch(match, "<span class=""luna-exam.+?>.+?</span>", example)
- tmp := RegExReplace(match, "<span class=""luna-exam.+?>.+?</span>", "")
- tmp := RegExReplace(tmp, "<.+?>", "")
- example := RegExReplace(example, "<.+?>", "")
- Result .= "`t" tmp "`n`t`t" example "`n`n"
- }
- ;Result .= (Result ? "`n`n" : "")
- ;. Variation
- ;. (Type ? "`n`t" . RegExReplace(Type, "<.+>") : "")
- ; Get rid of extra crap
- ;DefStart := InStr(A_LoopField, "<div class=""luna-Ent"">", false, 1, 2)
- ;Def := SubStr(A_LoopField, DefStart)
- ;Def := RegExReplace(Def, "<span class=""prondelim"">.*?Show IPA|<sup>\d*</sup>|<[^>]+>")
- ; Format defs that begin with a number
- ;Def := RegExReplace(Def, "i)(\d+\.)(\d+[^\d.]\d|[a-z(])", "`n`n`t`t$1 $u2")
- ;StringReplace Def, Def, `n`n, `n
- ; Format defs that begin with a letter
- ;Def := RegExReplace(Def, "(?:\.|\h)([a-z]\.)([^\h])", "`n`t`t`t$1 $u2")
- ; Format defs that don't begin with number or letter
- ;Def := RegExReplace(Def, "(\d\.\h\w+)\.\h(\w)", "$1`n`t`t`t$u2")
- ; If none of the format rules above applied
- ;if not InStr(Def, "`t")
- ;Def := RegExReplace(Def, "(.)(.+)", "`n`t`t$u1$2")
- Result := "" . WordWrap(Result, 110, 5)
- break
- }
- if (Result) {
- StringUpper Word, Word, T
- Gui Result:Show, , Word Definition
- GuiControl Result:, Wrd, %Word%
- GuiControl Result:, Def, %Result%
- }
- else {
- Gui Result:+OwnDialogs
- Result := RegExReplace(Html, "<[^>]+>")
- RegExMatch(Result, "Did you mean\K[^\n]+", Result)
- MsgBox, 68, Not Found, % "No definition was found for " Word "`n`n"
- . "Did you mean " Result "?"
- IfMsgBox Yes
- {
- Word := Result
- goto FindDef
- }
- }
- Result := Def := Html := ""
- return
- ResultGuiEscape:
- Gui Result:Cancel
- return
- UrlGet(url)
- {
- FileEncoding UTF-8
- TempFile := A_Temp "/" A_Now ".tmp"
- URLDownloadToFile % url, % TempFile
- FileRead out, % TempFile
- FileDelete % TempFile
- return out
- }
- ; Modified from st_wordwrap() by tidbit
- ; http://www.autohotkey.com/board/topic/90972-string-things-common-string-and-array-funcions/?p=574142
- ; string = what to Wrap, column = where to wrap, indent = Number of spaces to indent
- wordWrap(string, column = 56, Indent = 5)
- {
- Loop, Parse, string, `n, `r
- {
- StringReplace Line, A_LoopField, `t, % Spaces(Indent), UseErrorLevel
- IndentChar := Spaces((ErrorLevel + 1) * Indent)
- IndentLength := StrLen(IndentChar)
- If (StrLen(Line) > column)
- {
- pos := 1
- Loop, Parse, Line, %A_Space%
- If (pos + (loopLength := StrLen(A_LoopField)) <= column)
- out .= (A_Index = 1 ? "" : " ") A_LoopField
- , pos += loopLength + 1
- Else
- pos := loopLength + 1 + indentLength
- , out .= "`n" indentChar A_LoopField
- out .= "`n"
- } Else
- out .= Line "`n"
- }
- Return SubStr(out, 1, -1)
- }
- Spaces(n)
- {
- Loop % n
- out .= A_Space
- return out
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement