Advertisement
tabnation

google trans to eng

May 6th, 2021
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.74 KB | None | 0 0
  1. f1::
  2. clipboard=
  3. Send ^c
  4. sleep 250
  5. transeng := GoogleTranslate(clipboard)
  6. sleep 3000
  7. gui, destroy
  8. Gui, Font, s12
  9. Gui, Add, Edit, x12 y9 w770 h460 , %transeng%
  10. Gui, Show, x560 y271 h484 w799, Google Translate
  11. send {pgup 2}
  12. Return
  13. GoogleTranslate(str, from := "auto", to := "en") {
  14. static JS := GetJScripObject(), _ := JS.( GetJScript() ) := JS.("delete ActiveXObject; delete GetObject;")
  15. json := SendRequest(JS, str, to, from, proxy := "")
  16. oJSON := JS.("(" . json . ")")
  17. if !IsObject(oJSON[1]) {
  18. Loop % oJSON[0].length
  19. trans .= oJSON[0][A_Index - 1][0]
  20. }
  21. else {
  22. MainTransText := oJSON[0][0][0]
  23. Loop % oJSON[1].length {
  24. trans .= "`n+"
  25. obj := oJSON[1][A_Index-1][1]
  26. Loop % obj.length {
  27. txt := obj[A_Index - 1]
  28. trans .= (MainTransText = txt ? "" : "`n" txt)
  29. }
  30. }
  31. }
  32. if !IsObject(oJSON[1])
  33. MainTransText := trans := Trim(trans, ",+`n ")
  34. else
  35. trans := MainTransText . "`n+`n" . Trim(trans, ",+`n ")
  36. from := oJSON[2]
  37. trans := Trim(trans, ",+`n ")
  38. Return trans
  39. }
  40. SendRequest(JS, str, tl, sl, proxy) {
  41. ComObjError(false)
  42. http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  43. ( proxy && http.SetProxy(2, proxy) )
  44. http.open( "POST", "https://translate.google.com/translate_a/single?client=t&sl="
  45. . sl . "&tl=" . tl . "&hl=" . tl
  46. . "&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"
  47. . "&tk=" . JS.("tk").(str), 1 )
  48. http.SetRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8")
  49. http.SetRequestHeader("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:47.0) Gecko/20100101 Firefox/47.0")
  50. http.send("q=" . URIEncode(str))
  51. http.WaitForResponse(-1)
  52. Return http.responsetext
  53. }
  54. URIEncode(str, encoding := "UTF-8") {
  55. VarSetCapacity(var, StrPut(str, encoding))
  56. StrPut(str, &var, encoding)
  57. While code := NumGet(Var, A_Index - 1, "UChar") {
  58. bool := (code > 0x7F || code < 0x30 || code = 0x3D)
  59. UrlStr .= bool ? "%" . Format("{:02X}", code) : Chr(code)
  60. }
  61. Return UrlStr
  62. }
  63. GetJScript()
  64. {
  65. script =
  66. (
  67. var TKK = ((function() {
  68. var a = 561666268;
  69. var b = 1526272306;
  70. return 406398 + '.' + (a + b);
  71. })());
  72.  
  73. function b(a, b) {
  74. for (var d = 0; d < b.length - 2; d += 3) {
  75. var c = b.charAt(d + 2),
  76. c = "a" <= c ? c.charCodeAt(0) - 87 : Number(c),
  77. c = "+" == b.charAt(d + 1) ? a >>> c : a << c;
  78. a = "+" == b.charAt(d) ? a + c & 4294967295 : a ^ c
  79. }
  80. return a
  81. }
  82.  
  83. function tk(a) {
  84. for (var e = TKK.split("."), h = Number(e[0]) || 0, g = [], d = 0, f = 0; f < a.length; f++) {
  85. var c = a.charCodeAt(f);
  86. 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) ?
  87. (c = 65536 + ((c & 1023) << 10) + (a.charCodeAt(++f) & 1023), g[d++] = c >> 18 | 240,
  88. g[d++] = c >> 12 & 63 | 128) : g[d++] = c >> 12 | 224, g[d++] = c >> 6 & 63 | 128), g[d++] = c & 63 | 128)
  89. }
  90. a = h;
  91. for (d = 0; d < g.length; d++) a += g[d], a = b(a, "+-a^+6");
  92. a = b(a, "+-3^+b+-f");
  93. a ^= Number(e[1]) || 0;
  94. 0 > a && (a = (a & 2147483647) + 2147483648);
  95. a `%= 1E6;
  96. return a.toString() + "." + (a ^ h)
  97. }
  98. )
  99. Return script
  100. }
  101. GetJScripObject() {
  102. VarSetCapacity(tmpFile, (MAX_PATH := 260) << !!A_IsUnicode, 0)
  103. DllCall("GetTempFileName", Str, A_Temp, Str, "AHK", UInt, 0, Str, tmpFile)
  104. FileAppend,
  105. (
  106. <component>
  107. <public><method name='eval'/></public>
  108. <script language='JScript'></script>
  109. </component>
  110. ), % tmpFile
  111. JS := ObjBindMethod( ComObjGet("script:" . tmpFile), "eval" )
  112. FileDelete, % tmpFile
  113. Return JS
  114. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement