Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2020
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.85 KB | None | 0 0
  1. ; Autoexecute
  2. #NoEnv
  3. #SingleInstance force
  4. Process, priority, , High
  5. SetMouseDelay, -1
  6. SetBatchLines, -1
  7. SetControlDelay, -1
  8. SetKeyDelay, -1
  9. SetWinDelay, -1
  10.  
  11. Gui Result:Color, F0F0F0
  12. Gui Result:Font, s10 bold, Verdana
  13. Gui Result:Add, Text, w800 r1 vWrd
  14. Gui Result:Font, norm
  15. Gui Result:Add, Edit, w800 r30 vDef t15 +ReadOnly -Wrap HScroll
  16.  
  17.  
  18. ;//COPYING WORDS TO REMEMBER IN TEXT FILE//
  19.  
  20. FileName := "C:\Program Files\AutoHotkey\newwords.txt"
  21.  
  22.  
  23.  
  24.  
  25.  
  26. !`::Run Edit "C:\Program Files\AutoHotkey\newwords.txt"
  27. return
  28.  
  29.  
  30. ^`::
  31. FileAppend, % get_Highlight() "`n", %FileName%
  32.  
  33.  
  34. ;-------------------------------------------------------------------------------
  35. get_Highlight() { ; get highlighted text
  36. ;-------------------------------------------------------------------------------
  37. ClipStore := Clipboard ; store current content
  38. Clipboard = ; empty
  39. SendInput, ^c ; copy highlighted text
  40. ClipWait ; wait for change
  41. Result := Clipboard ; store highlighted text
  42. Clipboard := ClipStore ; restore clipboard's previous content
  43. Return, Result
  44. }
  45. return
  46.  
  47.  
  48.  
  49.  
  50. ;//
  51.  
  52. +`::
  53. InputBox Word, Define Word, Enter word to define., , 150, 120
  54. if (ErrorLevel)
  55. return
  56. Word := RegExReplace(Word, "[^\w\s]")
  57. StringLower Word, Word
  58. gosub FindDef
  59. return
  60.  
  61. `::
  62. Send {LButton}
  63. Send {LButton}
  64. SaveClip := ClipboardAll
  65. Clipboard := ""
  66. Send ^c
  67. ClipWait 1
  68. Word := RegExReplace(Clipboard, "[^\w\s]")
  69. Clipboard := SaveClip
  70. SaveClip := ""
  71. if (Word) {
  72. StringLower Word, Word
  73. gosub FindDef
  74. }
  75. return
  76.  
  77.  
  78. ;^R:: Reload
  79.  
  80.  
  81.  
  82. FindDef:
  83. if !Html := UrlGet("https://www.dictionary.com/browse/" Word "?s=t") {
  84. MsgBox No data returned from Dictionary.com
  85. return
  86. }
  87.  
  88. Loop Parse, Html, `n, `r
  89. {
  90. ; if SubStr(A_LoopField, 8, 46) <> "<!-- Google Analytics GTM iframe ends here -->"
  91. if InStr(A_LoopField, "<div id=""root""><div data-reactroot="""">") == 0
  92. continue
  93.  
  94. ; Variations - different forms of word entered
  95. ; Type - noun, verb, adjective, etc.
  96. ;RegExMatch(A_LoopField, "([^>]+)(?=</h2>)", Variation)
  97.  
  98. Result := ""
  99.  
  100. Pos=1
  101. While Pos := RegExMatch(A_LoopField, "<div value=.+?>.+?</div>", match ,Pos+StrLen(match))
  102. {
  103. example := ""
  104. RegExMatch(match, "<span class=""luna-exam.+?>.+?</span>", example)
  105. tmp := RegExReplace(match, "<span class=""luna-exam.+?>.+?</span>", "")
  106. tmp := RegExReplace(tmp, "<.+?>", "")
  107. example := RegExReplace(example, "<.+?>", "")
  108. Result .= "`t" tmp "`n`t`t" example "`n`n"
  109. }
  110. ;Result .= (Result ? "`n`n" : "")
  111.  
  112. ;. Variation
  113. ;. (Type ? "`n`t" . RegExReplace(Type, "<.+>") : "")
  114.  
  115.  
  116.  
  117. ; Get rid of extra crap
  118. ;DefStart := InStr(A_LoopField, "<div class=""luna-Ent"">", false, 1, 2)
  119. ;Def := SubStr(A_LoopField, DefStart)
  120. ;Def := RegExReplace(Def, "<span class=""prondelim"">.*?Show IPA|<sup>\d*</sup>|<[^>]+>")
  121.  
  122. ; Format defs that begin with a number
  123. ;Def := RegExReplace(Def, "i)(\d+\.)(\d+[^\d.]\d|[a-z(])", "`n`n`t`t$1 $u2")
  124. ;StringReplace Def, Def, `n`n, `n
  125.  
  126. ; Format defs that begin with a letter
  127. ;Def := RegExReplace(Def, "(?:\.|\h)([a-z]\.)([^\h])", "`n`t`t`t$1 $u2")
  128.  
  129. ; Format defs that don't begin with number or letter
  130. ;Def := RegExReplace(Def, "(\d\.\h\w+)\.\h(\w)", "$1`n`t`t`t$u2")
  131.  
  132. ; If none of the format rules above applied
  133. ;if not InStr(Def, "`t")
  134. ;Def := RegExReplace(Def, "(.)(.+)", "`n`t`t$u1$2")
  135.  
  136. Result := "" . WordWrap(Result, 110, 5)
  137. break
  138. }
  139.  
  140.  
  141. if (Result) {
  142. StringUpper Word, Word, T
  143. Gui Result:Show, , Word Definition
  144. GuiControl Result:, Wrd, %Word%
  145. GuiControl Result:, Def, %Result%
  146. }
  147. else {
  148. Gui Result:+OwnDialogs
  149. Result := RegExReplace(Html, "<[^>]+>")
  150. RegExMatch(Result, "Did you mean\K[^\n]+", Result)
  151. MsgBox, 68, Not Found, % "No definition was found for " Word "`n`n"
  152. . "Did you mean " Result "?"
  153. IfMsgBox Yes
  154. {
  155. Word := Result
  156. goto FindDef
  157. }
  158. }
  159. Result := Def := Html := ""
  160. return
  161.  
  162. ResultGuiEscape:
  163. Gui Result:Cancel
  164. return
  165.  
  166. UrlGet(url)
  167. {
  168. FileEncoding UTF-8
  169. TempFile := A_Temp "/" A_Now ".tmp"
  170. URLDownloadToFile % url, % TempFile
  171. FileRead out, % TempFile
  172. FileDelete % TempFile
  173. return out
  174. }
  175.  
  176. ; Modified from st_wordwrap() by tidbit
  177. ; http://www.autohotkey.com/board/topic/90972-string-things-common-string-and-array-funcions/?p=574142
  178. ; string = what to Wrap, column = where to wrap, indent = Number of spaces to indent
  179. wordWrap(string, column = 56, Indent = 5)
  180. {
  181. Loop, Parse, string, `n, `r
  182. {
  183. StringReplace Line, A_LoopField, `t, % Spaces(Indent), UseErrorLevel
  184. IndentChar := Spaces((ErrorLevel + 1) * Indent)
  185. IndentLength := StrLen(IndentChar)
  186. If (StrLen(Line) > column)
  187. {
  188. pos := 1
  189. Loop, Parse, Line, %A_Space%
  190. If (pos + (loopLength := StrLen(A_LoopField)) <= column)
  191. out .= (A_Index = 1 ? "" : " ") A_LoopField
  192. , pos += loopLength + 1
  193. Else
  194. pos := loopLength + 1 + indentLength
  195. , out .= "`n" indentChar A_LoopField
  196.  
  197. out .= "`n"
  198. } Else
  199. out .= Line "`n"
  200. }
  201.  
  202. Return SubStr(out, 1, -1)
  203. }
  204.  
  205. Spaces(n)
  206. {
  207. Loop % n
  208. out .= A_Space
  209. return out
  210. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement