Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.62 KB | None | 0 0
  1. #NoEnv
  2. #SingleInstance FORCE
  3. #Persistent
  4. SetCapsLockState, Off
  5. SetTimer, RestartScript, 1200000
  6. SetBatchLines, -1
  7. ; Check every second if CapsLock is off
  8. SetTimer, keepCapsLockOff, 1000
  9.  
  10. keepCapsLockOff()
  11. {
  12. SetCapsLockState Off
  13. }
  14.  
  15. Global guiHandle
  16. Global Extend:=200
  17. Global lastExtended:=0 , Extended:=0
  18. Global guiTitle:="Tu Dien Han-Viet"
  19. Global guiW:=600
  20. Global guiH:=A_ScreenHeight-300
  21. ;~ Global spVoice:=ComObjCreate("SAPI.SpVoice")
  22. ;~ SpVoice.Voice:=SpVoice.GetVoices("Name=Microsoft Heami Desktop").Item(0)
  23. _InitGUI()
  24. return
  25.  
  26. RestartScript:
  27. ;~ MsgBox, 4, Restarting dictionary script, Restarting dictionary script. Select 'no' in the next 10 seconds to cancel. Otherwise wait 10 seconds or hit 'yes'., 10
  28. ;~ IfMsgBox, No
  29. ;~ return
  30. Run, "%A_AhkPath%" /r "%A_ScriptFullPath%"
  31.  
  32.  
  33. #iF,% WinExist("ahk_id" guiHandle)
  34. ~*LShift::
  35. GuiEscape:
  36. Gui,Hide
  37. DllCall("psapi.dll\EmptyWorkingSet","UInt",-1)
  38. return
  39. #iF
  40.  
  41. ;~ #iF,% WinActive("ahk_id" guiHandle)
  42. ;~ Enter::
  43. ;~ Temp:=Clipboard
  44. ;~ Clipboard:=""
  45. ;~ Send ^c
  46. ;~ ClipWait 2
  47. ;~ iF ErrorLevel
  48. ;~ {
  49. ;~ Clipboard:=Temp
  50. ;~ return
  51. ;~ }
  52. ;~ TextToSpeech:=Trim(Clipboard)
  53. ;~ Clipboard:=Temp
  54. ;~ spVoice.Speak(TextToSpeech,0x1|0x2)
  55. ;~ return
  56. #iF
  57. ;^1::bool := !bool
  58.  
  59. Ctrl::
  60. ; if(bool) {
  61. Temp:=Clipboard
  62. Clipboard:=""
  63. Send ^c
  64. ClipWait 2
  65. iF ErrorLevel
  66. {
  67. Clipboard:=Temp
  68. return
  69. }
  70. ;}
  71. ;LAlt::
  72. Text:=Trim(Clipboard)
  73. Clipboard:=Temp
  74. WinGet,MinMax,MinMax,ahk_id %guiHandle%
  75. iF MinMax=-1
  76. WinRestore,ahk_id %guiHandle%
  77. iF StrLen(Text)>1000
  78. return
  79. GuiControl,Show,WB
  80. ;~ GuiControl,Hide,WB2
  81. ;~ GuiControl,Hide,WB3
  82. GuiControl,Focus,WB
  83. DetectHiddenWindows OFF
  84.  
  85. GuiControl,Hide,WBedit
  86. GuiControl,Move,WB,% "y0 h" guiH-40
  87. ;~ GuiControl,Move,WB2,% "y0 h" guiH-40
  88. ;~ GuiControl,Move,WB3,% "y0 h" guiH-40
  89. iF not WinExist("ahk_id " guiHandle)
  90. {
  91. ;~ iF not Pos
  92. ;~ {
  93. Pos:=ActiveMonitorCoordinates()
  94. x := Pos[3]+Pos[1] - guiW - 160
  95. y := 0
  96. Gui,Show,% "x" x " y" y " w" guiW+(lastExtended*Extend) " h" guiH,% guiTitle
  97. ;~ }
  98. ;~ else
  99. ;~ {
  100. ;~ DetectHiddenWindows ON
  101. ;~ WinGetPos,guiX,,,,ahk_id %guiHandle%
  102. ;~ Gui,Show,% "w" guiW " x" guiX+(lastExtended*Extend) " h" guiH,% guiTitle
  103. ;~ }
  104. }
  105. else
  106. {
  107. WinGetPos,guiX,,,,ahk_id %guiHandle%
  108. Gui,Show,% "w" guiW " x" guiX+(lastExtended*Extend) " h" guiH,% guiTitle
  109. }
  110. Try WB.Navigate("https://dict.naver.com/vikodict/vietnamese/#/search?query=" UrlEncode(Text))
  111. Catch
  112. Try WB.Navigate("https://dict.naver.com/vikodict/vietnamese/#/search?query=" UrlEncode2(Text))
  113. ;~ Try WB2.Navigate("http://m.endic.naver.com/search.nhn?searchOption=all&query=" UrlEncode(Text)) ;English
  114. ;~ Catch
  115. ;~ WB2.Navigate("http://m.endic.naver.com/search.nhn?searchOption=all&query=" UrlEncode2(Text)) ;English
  116. ;~ Try WB3.Navigate("https://ko.dict.naver.com/#/search?query=" UrlEncode(Text)) ;Korean
  117. ;~ Catch
  118. ;~ WB3.Navigate("https://ko.dict.naver.com/#/search?query=" UrlEncode2(Text)) ;Korean
  119. ;SetTimer,Translate,-0
  120. return
  121.  
  122. GuiSize:
  123. iF A_EventInfo=1 ;The window has been minimized, no action needed
  124. return
  125. DetectHiddenWindows OFF
  126. iF WinExist("ahk_id " guiHandle)
  127. {
  128. ;WinGetClientSize(guiHandle,newW,newH)
  129. WinGetPos,,,newW,,ahk_id %guiHandle%
  130. ;GuiControl,Move,Button1,% "x" 0 " w" guiW/3+(Extended*Extend)
  131. ;GuiControl,Move,Button2,% "x" (guiW/1.5)+(Extended*Extend)
  132. ;GuiControl,Move,Button3,% "x" (guiW/3)+(Extended*Extend)
  133.  
  134. GuiControl,Move,Button1,% "x" 0 " w" (guiW+Extended*Extend) ;"x" 0+(Extended*Extend)
  135. ;~ GuiControl,Move,Button2,% "x" (guiW+Extended*Extend)/3 " w" (guiW+Extended*Extend)/3
  136. ;~ GuiControl,Move,Button3,% "x" (guiW+Extended*Extend)/3*2 " w" (guiW+Extended*Extend)/3
  137. }
  138. return
  139.  
  140. ActiveMonitorCoordinates() ;by Ħakito
  141. {
  142. ;~ SysGet,PhysicalMonitors,80
  143. ;~ CoordMode,Mouse,Screen
  144. ;~ MouseGetPos,mouseX,mouseY
  145. ;~ Loop %PhysicalMonitors%
  146. ;~ {
  147. ;~ SysGet,Position,Monitor,%A_Index%
  148. ;~ iF(mouseX>=PositionLeft and mouseY>=PositionTop and mouseX<PositionRight and mouseY<PositionBottom)
  149. ;~ {
  150. ;~ Monitor:=A_Index
  151. ;~ }
  152. ;~ }
  153. ;~ iF(Monitor="")
  154. ;~ Monitor:=0
  155. Monitor :=1
  156. SysGet Pos,Monitor,%Monitor%
  157. return [PosLeft,PosTop,PosRight-PosLeft,PosBottom-PosTop]
  158. }
  159.  
  160. _InitGUI() {
  161. Global
  162. Local Pos,x,y
  163.  
  164. Pos:=ActiveMonitorCoordinates()
  165. x := Pos[3]+Pos[1] - guiW - 10
  166. y :=0
  167.  
  168. Gui,+AlwaysOnTop +HWNDguiHandle
  169. Gui,Margin, 0, 0
  170. Gui,Add,ActiveX,% "x0 y63 w" guiW " h" guiH-103 " vWB", Shell.Explorer ;Vietnamese
  171. ;~ Gui,Add,ActiveX,% "x0 y63 w" guiW " h" guiH-103 " vWB2 Hidden", Shell.Explorer ;English
  172. ;~ Gui,Add,ActiveX,% "x0 y63 w" guiW " h" guiH-103 " vWB3 Hidden", Shell.Explorer ;Korean
  173. WB.Silent:=True
  174. ;~ WB2.Silent:=True , WB3.Silent:=True
  175. ;Gui, Color, Black
  176. Gui,Add,Button,% "h40 x0 y" guiH-40 " w" guiW , Hien Lucy 안녕하세요!
  177. ;~ Gui,Add,Button,% "h40 x0 y" guiH-40 " w" guiW/3 " gChangeLanguage vButton2",English
  178. ;~ Gui,Add,Button,% "h40 x0 y" guiH-40 " w" guiW/3 " gChangeLanguage vButton3",Korean
  179. Gui,Font, cFFFFFF s12 w600,Sans Serif
  180. Gui,Color,c00C73C,c00C73C
  181. ;Gui, Color, 4D00FF
  182. ;~ Gui,Add,Edit,% "x3 y3 w" guiW-6 " h" 60 " vWBedit +0x100 +0x200 -E0x200 -HScroll -VScroll" ;Translation to English
  183. Gui,Show,Hide x%x% y%y% w%guiW% h%guiH%,% guiTitle
  184. WB.Navigate("about:blank")
  185. ;~ WB2.Navigate("about:blank")
  186. ;~ WB3.Navigate("about:blank")
  187. While WB.readystate != 4 or WB.busy
  188. Sleep 5
  189.  
  190. ComObjConnect(WB, "WB_")
  191. ;~ ComObjConnect(WB2, "WB_")
  192. ;~ ComObjConnect(WB3, "WB_")
  193. ComObjConnect(WBdocument:=WB.document, "WBdocument_")
  194. ;~ ComObjConnect(WB2document:=WB2.document, "WB2document_")
  195. ;~ ComObjConnect(WB3document:=WB3.document, "WB3document_")
  196. WB.Navigate("https://dict.naver.com/vikodict/vietnamese/#/search?query=loading") ;Vietnamese
  197. ;WB2.Navigate("http://m.endic.naver.com/search.nhn?searchOption=all&query=loading") ;English
  198. ;WB3.Navigate("https://ko.dict.naver.com/search/all/0/loading/?format=HTML&isMobile=true&isReDirect=false") ;Korean
  199. return
  200. }
  201.  
  202. ;~ ChangeLanguage:
  203. ;~ Critical
  204. ;~ iF(A_GuiControl="Button1") ;Vietnamese
  205. ;~ {
  206. ;~ GuiControl,Show,WB
  207. ;~ GuiControl,Hide,WB2
  208. ;~ GuiControl,Hide,WB3
  209. ;~ GuiControl,Focus,WB
  210. ;~ }
  211. ;~ else iF(A_GuiControl="Button2") ;English
  212. ;~ {
  213. ;~ GuiControl,Hide,WB
  214. ;~ GuiControl,Show,WB2
  215. ;~ GuiControl,Hide,WB3
  216. ;~ GuiControl,Focus,WB2
  217. ;~ ;WB2.Document.Write("") ;Clears the page
  218.  
  219. ;~ }
  220. ;~ else iF(A_GuiControl="Button3") ;Korean
  221. ;~ {
  222. ;~ GuiControl,Hide,WB
  223. ;~ GuiControl,Hide,WB2
  224. ;~ GuiControl,Show,WB3
  225. ;~ GuiControl,Focus,WB3
  226. ;~ ;WB3.Document.Write("") ;Clears the page
  227. ;~ }
  228. ;~ return
  229.  
  230. WB_NavigateComplete2(pDisp,URL,WB)
  231. {
  232. Global
  233. Local divTags:=WB.Document.All.Tags("div")
  234. Loop % divTags.length
  235. {
  236. iF divTags[A_Index-1].ClassName="mykeyword_wrap opened"
  237. {
  238. divTags[A_Index-1].OuterHtml:=""
  239. return ;Returns nothing
  240. }
  241. }
  242. }
  243.  
  244. WBdocument_OnKeyPress(p*) ;By jethrow, it fixes Ctrl+X/C/V etc - https://autohotkey.com/board/topic/76777-help-with-copy-and-pasting-with-shellexplorer/
  245. {
  246. Global
  247. Static Keys:={1:"selectall", 3:"copy", 13:"enter", 22:"paste", 24:"cut", 25:"redo", 26:"undo"}
  248. Local keyCode
  249. iF Keys.HasKey(keyCode:=WBdocument.parentWindow.event.keyCode)
  250. WBdocument.ExecCommand(Keys[keyCode])
  251. }
  252.  
  253.  
  254. ;~ WB2document_OnKeyPress(p*) ;By jethrow, it fixes Ctrl+X/C/V etc - https://autohotkey.com/board/topic/76777-help-with-copy-and-pasting-with-shellexplorer/
  255. ;~ {
  256. ;~ Global
  257. ;~ Static Keys:={1:"selectall", 3:"copy", 13:"enter", 22:"paste", 24:"cut", 25:"redo", 26:"undo"}
  258. ;~ Local keyCode
  259. ;~ iF Keys.HasKey(keyCode:=WB2document.parentWindow.event.keyCode)
  260. ;~ WB2document.ExecCommand(Keys[keyCode])
  261. ;~ }
  262. ;~ WB3document_OnKeyPress(p*) ;By jethrow, it fixes Ctrl+X/C/V etc - https://autohotkey.com/board/topic/76777-help-with-copy-and-pasting-with-shellexplorer/
  263. ;~ {
  264. ;~ Global
  265. ;~ Static Keys:={1:"selectall", 3:"copy", 13:"enter", 22:"paste", 24:"cut", 25:"redo", 26:"undo"}
  266. ;~ Local keyCode
  267. ;~ iF Keys.HasKey(keyCode:=WB3document.parentWindow.event.keyCode)
  268. ;~ WB3document.ExecCommand(Keys[keyCode])
  269. ;~ }
  270.  
  271.  
  272.  
  273. UrlEncode2(Str, All := False) ;From https://autohotkey.com/boards/viewtopic.php?t=2477
  274. {
  275. Static doc := ComObjCreate("HTMLfile")
  276. Try
  277. {
  278. doc.write("<body><script>document.body.innerText = encodeURI" . (All ? "Component" : "") . "(""" . Str . """);</script>")
  279. Return, doc.body.innerText, doc.body.innerText := ""
  280. }
  281. }
  282. UrlDecode2(Str)
  283. {
  284. Static doc := ComObjCreate("HTMLfile")
  285. Try
  286. {
  287. doc.write("<body><script>document.body.innerText = decodeURIComponent(""" . Str . """);</script>")
  288. Return, doc.body.innerText, doc.body.innerText := ""
  289. }
  290. }
  291.  
  292.  
  293.  
  294. ;########################################################################### ###########################################################################
  295. ;########################################################################### TRANSLATE ###########################################################################
  296. ;########################################################################### ###########################################################################
  297. Translate:
  298. Critical OFF
  299. Translation:=GoogleTranslate(Text).main
  300. GuiControl,,WBedit,% Translation
  301. ;Gui,Show,NA,% "EN: " Translation
  302. return
  303.  
  304. CapsLock::
  305. Temp:=Clipboard
  306. ;~ Clipboard:=""
  307. ;~ SendInput ^c
  308. ;~ ClipWait 2
  309. ;~ iF ErrorLevel
  310. ;~ {
  311. ;~ Clipboard:=Temp
  312. ;~ Return
  313. ;~ }
  314. ;~ Text:=Clipboard
  315. Clipboard:=Temp
  316. DetectHiddenWindows OFF
  317. GuiControl,Show,WBedit
  318. GuiControl,Move,WB,% "y63 h" guiH-103
  319. ;~ GuiControl,Move,WB2,% "y63 h" guiH-103
  320. ;~ GuiControl,Move,WB3,% "y63 h" guiH-103
  321. iF not WinExist("ahk_id " guiHandle)
  322. {
  323. DetectHiddenWindows ON
  324. WinGetPos,guiX,,,,ahk_id %guiHandle%
  325. Gui,Show,% "w" guiW " x" guiX+(Extended*Extend) " h63",% "Translation to English"
  326. lastExtended:=Extended:=0
  327. }
  328. Goto,Translate
  329.  
  330. return
  331.  
  332. ;~ /*
  333. ;~ F12::
  334. ;~ Result:=GoogleTranslate("테스트")
  335. ;~ Msgbox % Result.From
  336. ;~ return
  337. ;~ */
  338.  
  339. GoogleTranslate(str, from := "auto", to := "en")
  340. {
  341. JSON:=new JSON
  342. JS:=JSON.JS
  343. JS.(GetJScript())
  344.  
  345. sJson:=SendRequest(JS,str,to,from)
  346. oJSON:=JSON.Parse(sJson)
  347.  
  348. if !IsObject(oJSON[2]) {
  349. for k, v in oJSON[1]
  350. trans .= v[1]
  351. }
  352. else {
  353. MainTransText := oJSON[1, 1, 1]
  354. for k, v in oJSON[2] {
  355. trans .= "`n+"
  356. for i, txt in v[2]
  357. trans .= (MainTransText = txt ? "" : "`n" . txt)
  358. }
  359. }
  360. if !IsObject(oJSON[2])
  361. MainTransText := trans := Trim(trans, ",+`n ")
  362. else
  363. trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")
  364.  
  365. from := oJSON[3]
  366. trans := Trim(trans, ",+`n ")
  367. Return {main: MainTransText, full: trans, from: from, sJson: sJson}
  368. }
  369.  
  370. SendRequest(JS, str, tl, sl) {
  371. ComObjError(false)
  372. url := "https://translate.google.com/translate_a/single?client=t&sl="
  373. . sl . "&tl=" . tl . "&hl=" . tl
  374. . "&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"
  375. . "&tk=" . JS.("tk").(str)
  376. body := "q=" UrlEncode(str)
  377. contentType := "application/x-www-form-urlencoded;charset=utf-8"
  378. userAgent := "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0"
  379. Return JSON.GetFromUrl(url, body, contentType, userAgent)
  380. }
  381.  
  382. UrlEncode(str, encoding := "UTF-8") {
  383. VarSetCapacity(var, StrPut(str, encoding))
  384. StrPut(str, &var, encoding)
  385.  
  386. While code := NumGet(Var, A_Index - 1, "UChar") {
  387. bool := (code > 0x7F || code < 0x30 || code = 0x3D)
  388. UrlStr .= bool ? "%" . Format("{:02X}", code) : Chr(code)
  389. }
  390. Return UrlStr
  391. }
  392.  
  393. GetJScript()
  394. {
  395. script =
  396. (
  397. var TKK = ((function() {
  398. var a = 561666268;
  399. var b = 1526272306;
  400. return 406398 + '.' + (a + b);
  401. })());
  402.  
  403. function b(a, b) {
  404. for (var d = 0; d < b.length - 2; d += 3) {
  405. var c = b.charAt(d + 2),
  406. c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c),
  407. c = "+" == b.charAt(d + 1) ? a >>> c : a << c;
  408. a = "+" == b.charAt(d) ? a + c & 4294967295 : a ^ c
  409. }
  410. return a
  411. }
  412.  
  413. function tk(a) {
  414. for (var e = TKK.split("."), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) {
  415. var c = a.charCodeAt(f);
  416. 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) ?
  417. (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240,
  418. g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128)
  419. }
  420. a = h;
  421. for (d = 0; d < g.length; d++) a += g[d], a = b(a, "+-a^+6");
  422. a = b(a, "+-3^+b+-f");
  423. a ^= Number(e[1]) || 0;
  424. 0 > a && (a = (a & 2147483647) + 2147483648);
  425. a `%= 1E6;
  426. return a.toString() + "." + (a ^ h)
  427. }
  428. )
  429. Return script
  430. }
  431.  
  432. class JSON
  433. {
  434. static JS := JSON._GetJScripObject()
  435.  
  436. Parse(JsonString) {
  437. try oJSON := this.JS.("(" JsonString ")")
  438. catch {
  439. MsgBox, Wrong JsonString!
  440. Return
  441. }
  442. Return this._CreateObject(oJSON)
  443. }
  444.  
  445. GetFromUrl(url, body := "", contentType := "", userAgent := "") {
  446. XmlHttp := ComObjCreate("Microsoft.XmlHttp")
  447. XmlHttp.Open("GET", url, false)
  448. ( contentType && XmlHttp.SetRequestHeader("Content-Type", contentType) )
  449. ( userAgent && XmlHttp.SetRequestHeader("User-Agent", userAgent) )
  450. XmlHttp.Send(body)
  451. Return XmlHttp.ResponseText
  452. }
  453.  
  454. _GetJScripObject() {
  455. VarSetCapacity(tmpFile, (MAX_PATH := 260) << !!A_IsUnicode, 0)
  456. DllCall("GetTempFileName", Str, A_Temp, Str, "AHK", UInt, 0, Str, tmpFile)
  457.  
  458. FileAppend,
  459. (
  460. <component>
  461. <public><method name='eval'/></public>
  462. <script language='JScript'></script>
  463. </component>
  464. ), % tmpFile
  465.  
  466. JS := ObjBindMethod( ComObjGet("script:" . tmpFile), "eval" )
  467. FileDelete, % tmpFile
  468. JSON._AddMethods(JS)
  469. Return JS
  470. }
  471.  
  472. _AddMethods(ByRef JS) {
  473. JScript =
  474. (
  475. Object.prototype.GetKeys = function () {
  476. var keys = []
  477. for (var k in this)
  478. if (this.hasOwnProperty(k))
  479. keys.push(k)
  480. return keys
  481. }
  482. Object.prototype.IsArray = function () {
  483. var toStandardString = {}.toString
  484. return toStandardString.call(this) == '[object Array]'
  485. }
  486. )
  487. JS.("delete ActiveXObject; delete GetObject;")
  488. JS.(JScript)
  489. }
  490.  
  491. _CreateObject(ObjJS) {
  492. res := ObjJS.IsArray()
  493. if (res = "")
  494. Return ObjJS
  495.  
  496. else if (res = -1) {
  497. obj := []
  498. Loop % ObjJS.length
  499. obj[A_Index] := this._CreateObject(ObjJS[A_Index - 1])
  500. }
  501. else if (res = 0) {
  502. obj := {}
  503. keys := ObjJS.GetKeys()
  504. Loop % keys.length
  505. k := keys[A_Index - 1], obj[k] := this._CreateObject(ObjJS[k])
  506. }
  507. Return obj
  508. }
  509. }
  510.  
  511. ;#####################################################################################WinGetClientSize
  512. WinGetClientSize(windowID:="A",ByRef Width:="OutputW",ByRef Height:="OutputH") ;by jNizM
  513. {
  514. DetectHiddenWindows ON
  515. iF(windowID="A" or windowID="Active")
  516. WinGet windowID,ID,A
  517. VarSetCapacity(Output,16)
  518. DllCall("GetClientRect","uint",windowID,"uint",&Output)
  519. Width:=NumGet(Output,8,"int")
  520. Height:=NumGet(Output,12,"int")
  521. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement