austinh115

Untitled

Jun 11th, 2018
465
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.37 KB | None | 0 0
  1. "use strict";
  2. var PageJson, websocket, appframeLoaded, OfflinePushToken, radio, Page = "",
  3. LastActionHero = "",
  4. SavedId = "",
  5. https = "https:",
  6. ConsoleOff = false,
  7. w_Vol = [35, 35, 35],
  8. w_sound = 1,
  9. ReleaseMode = 0,
  10. xConfig = {
  11. name: "box",
  12. origin: "file://",
  13. debugLogIgnore: [],
  14. debugNoLogs: false
  15. };
  16. xConfig.origin = "https://xat.com", xConfig.debugNoLogs = false, console.log = function(i, a, s) {
  17. return function() {
  18. if (1 != xConfig.debugNoLogs) {
  19. var e = new Array;
  20. for (var o in arguments) 0 != o || "." != arguments[0].toString()[0] ? (0 == o && e.push("." + a), e.push(arguments[o])) : e.push("." + a + arguments[0].toString());
  21. var t = e[0].toString();
  22. for (var n in s)
  23. if (t.startsWith(s[n])) return;
  24. return i.apply(this, e)
  25. }
  26. }
  27. }(console.log.bind(console), xConfig.name, xConfig.debugLogIgnore);
  28. var trace = console.log,
  29. sp_ids = ["home", "profile", "friends", "chats", "groups", "settings", "store", "buy", "help", "visitors", "classic"];
  30. for (var i in sp_ids) {
  31. var j = document.getElementById("sp_" + sp_ids[i]);
  32. j && (j.sp = sp_ids[i], j.addEventListener("click", function(e) {
  33. actSetPage(e.currentTarget.sp)
  34. }))
  35. }
  36.  
  37. function activityMain() {
  38. var e = activityToC("xatInit", "", "");
  39. console.log("Done xatInit"), setPage(ClassicGroup ? "classic" : 0 == e ? "profile" : "chats");
  40. activityToC("setContacts", "", ""), activityToC("xatMain", "", ""), console.log("Done xatMain"), activityToC("leaveBackground", "", ClassicGroup), ConsoleOff = false, activityToC("SetPhoneFontSize", "", "1.0"), activityToC("setLang", "", window.navigator.userLanguage || window.navigator.language), ClassicGroup && activityToC("xatCommand", "", JSON.stringify({
  41. Command: "StartGroup",
  42. Group: ClassicGroup
  43. })), setInterval(function() {
  44. TimerMethod()
  45. }, 100), activityToC("xatCommand", "", JSON.stringify({
  46. Command: "EnableTick"
  47. }))
  48. }
  49.  
  50. function setPage(e) {
  51. var o;
  52. if (e && ("pop" == e && "classic" == Page && (o = !0, e = Page), e = activityToC("SetPage", "", e), o || e != Page)) switch ("profile" == (Page = e) && (e = "actions"), activityToC("viewWillDisappear", "", ""), e) {
  53. case "captcha":
  54. var t = JSON.stringify(PageJson);
  55. (n = document.getElementById("appframe")).src = https + "//xat.com/web_gear/chat/AreYouaHuman.php?m=3&j=" + t;
  56. break;
  57. case "classic":
  58. default:
  59. var n;
  60. (n = document.getElementById("appframe")).onload = function(e) {
  61. appframeLoaded = !0, activityToC("webViewDidFinishLoad", "", "")
  62. }, n.src = "www/" + e + ".html"
  63. }
  64. }
  65.  
  66. function DoPageClick(e) {
  67. if ("string" == typeof e && (e = decodeURIComponent((e + "").replace(/\+/g, "%20")), e = JSON.parse(e)), "xtrace" != (PageJson = e).Type)
  68. if (PageJson.Page) {
  69. var o = PageJson.LastActionHero;
  70. o || (o = "");
  71. var t = PageJson.SavedId;
  72. t || (t = ""), LastActionHero == o && SavedId == t || activityToC("LastActionHero", LastActionHero = o, SavedId = t);
  73. var n = PageJson.Next;
  74. switch (PageJson.Command) {
  75. case "":
  76. case "NOP":
  77. case "HitWeb":
  78. break;
  79. case "Action":
  80. switch (PageJson.name) {
  81. case "BuyXats":
  82. case "MakePurchase":
  83. return
  84. }
  85. default:
  86. activityToC("xatCommand", "", JSON.stringify(PageJson))
  87. }
  88. ClassicGroup && "captcha" != n && "pop" != n || setPage(n)
  89. } else console.log("!!** No Page **!! ")
  90. }
  91. var encodings = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
  92.  
  93. function base64ArrayBuffer(e) {
  94. for (var o, t, n, i, a = "", s = new Uint8Array(e), r = s.byteLength, c = r % 3, l = r - c, d = 0; d < l; d += 3) o = (258048 & (i = s[d] << 16 | s[d + 1] << 8 | s[d + 2])) >> 12, t = (4032 & i) >> 6, n = 63 & i, a += encodings[(16515072 & i) >> 18] + encodings[o] + encodings[t] + encodings[n];
  95. return 1 == c ? (o = (3 & (i = s[l])) << 4, a += encodings[(252 & i) >> 2] + encodings[o] + "==") : 2 == c && (o = (1008 & (i = s[l] << 8 | s[l + 1])) >> 4, t = (15 & i) << 2, a += encodings[(64512 & i) >> 10] + encodings[o] + encodings[t] + "="), a
  96. }
  97.  
  98. function toUTF8ArrayBuf(e) {
  99. for (var o = [], t = 0; t < e.length; t++) {
  100. var n = e.charCodeAt(t);
  101. n < 128 ? o.push(n) : n < 2048 ? o.push(192 | n >> 6, 128 | 63 & n) : n < 55296 || 57344 <= n ? o.push(224 | n >> 12, 128 | n >> 6 & 63, 128 | 63 & n) : (t++, n = 65536 + ((1023 & n) << 10 | 1023 & e.charCodeAt(t)), o.push(240 | n >> 18, 128 | n >> 12 & 63, 128 | n >> 6 & 63, 128 | 63 & n))
  102. }
  103. var i = o.length,
  104. a = new ArrayBuffer(i),
  105. s = new Uint8Array(a);
  106. for (t = 0; t < i; t++) s[t] = o[t];
  107. return a
  108. }
  109.  
  110. function xatSend(e, o) {
  111. if (0 <= o.search("zz45") && (o = '<bs u="225248065" s="fred" />'), console.log("xatSend=" + e + "," + o), websocket) {
  112. var t = toUTF8ArrayBuf(o);
  113. websocket.send(t)
  114. }
  115. }
  116.  
  117. function xatClose() {
  118. isOpen = !1, console.log("xatClose"), websocket && (xatSend(0, "<C />"), websocket.close(), websocket = null)
  119. }
  120.  
  121. function DoNotify(e, o) {
  122. switch (e) {
  123. case "FifoNotification":
  124. if (!appframeLoaded) return;
  125. var t, n = JSON.parse(o);
  126. trace(n);
  127. for (var i = document.getElementById("appframe").contentWindow, a = 0; a < n.length; a++)
  128. if ("{" == n[a].charAt(0)) switch ((t = JSON.parse(n[a])).Command) {
  129. case "SendSound":
  130. w_Vol = [xInt(t[1]), xInt(t[2]), xInt(t[3])], w_sound = xInt(t.w_sound), i.SetSpkIcon && i.SetSpkIcon(w_sound, t.HasRadio);
  131. break;
  132. case "PlayRadio":
  133. if (radio && (radio.unload(), radio = null), !t.Radio || 0 == w_Vol[1] || 0 == (2 & w_sound)) break;
  134. (radio = new Howl({
  135. src: [t.Radio],
  136. html5: !0,
  137. volume: w_Vol[1] / 100
  138. })).play();
  139. break;
  140. case "PlaySound":
  141. break;
  142. case "ToSideapp":
  143. parent.sideframe && parent.sideframe.postMessage(JSON.stringify(t), xConfig.origin);
  144. break;
  145. case "setCount":
  146. setCount && setCount(t.setCount);
  147. break;
  148. case "LocalNotify":
  149. if (!LocalNotify) break;
  150. if (!document[hidden]) break;
  151. notify.show(t.n, t.t)
  152. } else try {
  153. i.eval(n[a].toString())
  154. } catch (e) {
  155. var s = n[a].toString().match(/^([a-z]*)\./);
  156. s && s[1] && !i[s[1]] || console.log("FIFO ERR " + e + " " + n[a].toString())
  157. }
  158. return;
  159. case "SetGroupsPage":
  160. return void setPage("groups");
  161. case "SetChatsPage":
  162. return void setPage("chats");
  163. case "SetMePage":
  164. return void setPage("profile");
  165. case "SetBackPage":
  166. return void setPage("pop");
  167. case "SetVisitors":
  168. return void(i = document.getElementById("appframe").contentWindow).openList(0, "visitors", 0);
  169. default:
  170. console.log("!!** DoNotify TODO **!!/", notify)
  171. }
  172. }
  173.  
  174. function DoAlert(e) {
  175. alert(e)
  176. }
  177.  
  178. function DoLangs(e, o) {}
  179. var ConnectIp, ConnectPort, ClassicGroup, LocalNotify, LOADURL = 1,
  180. SEND = 2,
  181. CLOSE = 3,
  182. CONNECT = 4,
  183. NOTIFY = 5,
  184. ALERT = 6,
  185. HTTP = 7,
  186. LANGS = 8,
  187. FINISHTRANSACTION = 9,
  188. LOG = 10,
  189. SAVESOL = 11,
  190. LOADSOL = 12,
  191. isOpen = !1;
  192.  
  193. function FromC(e, o, t) {
  194. switch (xInt(e)) {
  195. case SAVESOL:
  196. if ("undefined" == typeof Storage) break;
  197. localStorage.setItem(o, t);
  198. break;
  199. case LOADSOL:
  200. if ("undefined" == typeof Storage) break;
  201. localStorage.getItem(o), localStorage.setItem(o, t);
  202. break;
  203. case LOG:
  204. console.log(".FromC", t);
  205. break;
  206. case LOADURL:
  207. console.log("LOADURL," + o + "," + t);
  208. var n = new XMLHttpRequest,
  209. i = o;
  210. n.onreadystatechange = function() {
  211. 4 === n.readyState && (200 === n.status ? activityToC("xatURL", n.responseURL, n.responseText) : console.log("LOADURL Err:" + n.status))
  212. }, t ? (n.open("POST", i, !0), n.setRequestHeader("Content-type", "application/x-www-form-urlencoded"), n.send("json=" + t)) : (n.open("GET", i, !0), n.send());
  213. break;
  214. case SEND:
  215. console.log("SEND," + o + "," + t), xatSend(o, t);
  216. break;
  217. case CLOSE:
  218. console.log("CLOSE," + o + "," + t), xatClose();
  219. break;
  220. case CONNECT:
  221. o = "wss://wss.xatbox.com", t = 443, console.log("CONNECT," + o + "," + t), xatClose(), ConnectIp = o, ConnectPort = xInt(t) + "/v2", (websocket = new WebSocket(ConnectIp + ":" + ConnectPort)).binaryType = "arraybuffer", websocket.onopen = function(e) {
  222. isOpen = !0, activityToC("xatMessageReceived", "#CONNECT_OK", "")
  223. }, websocket.onclose = function(e) {
  224. 1e3 != e.code && console.log("WebSocket CLOSE ERROR:" + e.code), activityToC("xatMessageReceived", "#CONNECT_CLOSE", ""), isOpen = !1
  225. }, websocket.onmessage = function(e) {
  226. activityToC("xatMessageReceived", "#MESSAGE", base64ArrayBuffer(e.data))
  227. }, websocket.onerror = function(e) {
  228. console.log("WebSocket ERROR")
  229. };
  230. break;
  231. case NOTIFY:
  232. console.log(".FromCNotify", "NOTIFY," + o), DoNotify(o, t);
  233. break;
  234. case ALERT:
  235. DoAlert(o);
  236. break;
  237. case HTTP:
  238. https = "http:";
  239. break;
  240. case LANGS:
  241. DoLangs(o, t)
  242. }
  243. }
  244.  
  245. function TimerMethod() {
  246. for (var e = activityToC("xatTick", "", ""); e;) {
  247. var o = JSON.parse(e);
  248. o && FromC(o.Type, o.Cmd, o.Data), e = activityToC("ReadToJavaFifo", "", "")
  249. }
  250. OfflinePushToken && (activityToC("setToken", "", OfflinePushToken), OfflinePushToken = "")
  251. }
  252.  
  253. function xLog(e) {
  254. console.log(e)
  255. }
  256.  
  257. function onBackPressed() {
  258. console.log("onBackPressed"), setPage("pop")
  259. }
  260.  
  261. function xInt(e) {
  262. return e = parseInt(e), isNaN(e) ? 0 : e
  263. }
  264.  
  265. function activityToC(e, o, t) {
  266. "xatTick" != e && "ReadToJavaFifo" != e && console.log(".activityToC", e + " " + o + " " + t);
  267. var n = 2 * (2 * e.length + 1),
  268. i = Module._malloc(n);
  269. Module.stringToUTF8(e, i, n);
  270. var a = 2 * (2 * o.length + 1),
  271. s = Module._malloc(a);
  272. Module.stringToUTF8(o, s, a);
  273. var r = 2 * (2 * t.length + 1),
  274. c = Module._malloc(r);
  275. Module.stringToUTF8(t, c, r);
  276. var l = Module.ccall("cToC", null, ["number", "number", "number"], [i, s, c]),
  277. d = Pointer_stringify(l);
  278. return Module._free(l), d
  279. }
  280.  
  281. function setCount(e) {
  282. var o = document.getElementById("idactcount");
  283. 0 < e ? (9 < e && (e = "9+"), o.innerText = e, o.style.visibility = "visible") : o.style.visibility = "hidden"
  284. }
  285.  
  286. function onMore(e) {
  287. document.getElementById("dropdown-content").style.display = "block"
  288. }
  289.  
  290. function anyClick(e) {
  291. document.getElementById("dropdown-content").style.display = "none"
  292. }
  293.  
  294. function SetClassicMode(e) {
  295. if (e) {
  296. var o = document.getElementById("actionbar");
  297. o.style.height = "0%", o.style.display = "none", document.getElementById("app").style.height = "100%"
  298. }
  299. }
  300.  
  301. function actSetPage(e) {
  302. if ("buy" != e)
  303. if ("home" === e);
  304. else if ("classic" === e) {
  305. SetClassicMode(!0), document.getElementById("appframe").src = "www/classic.html", setPage(e)
  306. } else setPage(e);
  307. else window.open("https://xat.com/buy", "_blank")
  308. }
  309. document.addEventListener("click", anyClick, !0);
  310. var hidden, visibilityChange, Module = {
  311. preRun: [],
  312. postRun: [jsMain],
  313. print: function(e) {
  314. 1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" ")), e = String(e).replace(/\/n/g, "\n"), console.log("!print=" + e)
  315. },
  316. printErr: function(e) {
  317. 1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" ")), console.error("!printErr=" + e)
  318. },
  319. canvas: [],
  320. setStatus: function(e) {
  321. 1 < arguments.length && (e = Array.prototype.slice.call(arguments).join(" ")), console.log("!setStatus=" + e)
  322. },
  323. totalDependencies: 0,
  324. monitorRunDependencies: function(e) {
  325. this.totalDependencies = Math.max(this.totalDependencies, e), Module.setStatus(e ? "Preparing... (" + (this.totalDependencies - e) + "/" + this.totalDependencies + ")" : "All downloads complete.")
  326. }
  327. };
  328.  
  329. function jsMain() {
  330. parent && ((ClassicGroup = getParameterByName("gn", parent.window.location.href)) || (ClassicGroup = getParameterByName("id", parent.window.location.href)) && (ClassicGroup = "xat" + ClassicGroup)), ClassicGroup || (ClassicGroup = getParameterByName("n")), ClassicGroup || (ClassicGroup = "Lobby"), ClassicGroup && (ClassicGroup = ClassicGroup.replace(/[^0-9a-zA-Z_]/g, "")), ClassicGroup ? SetClassicMode(!0) : document.getElementById("actionbar").style.display = "block", notify.compatible() && notify.authorize(), activityMain()
  331. }
  332.  
  333. function getParameterByName(e, o) {
  334. o || (o = window.location.href), e = e.replace(/[\[\]]/g, "\\$&");
  335. var t = new RegExp("[?&]" + e + "(=([^&#]*)|&|#|$)").exec(o);
  336. return t ? t[2] ? decodeURIComponent(t[2].replace(/\+/g, " ")) : "" : null
  337. }
  338.  
  339. function getAnchor(e) {
  340. return e.substring(e.indexOf("#") + 1)
  341. }
  342.  
  343. function onMessage(e) {
  344. if (e.origin === xConfig.origin) {
  345. var o = JSON.parse(e.data);
  346. trace(o), activityToC("xatCommand", "", JSON.stringify({
  347. Command: "lcAppToChat",
  348. channel: o.channel,
  349. user: o.user,
  350. msg: o.msg
  351. }))
  352. } else trace("onMessage Bad Origin=", e.origin, e)
  353. }
  354.  
  355. function handleVisibilityFocusChange() {}
  356.  
  357. function loadJsModule(n, i) {
  358. return new Promise(function(e, o) {
  359. var t = document.createElement("script");
  360. t.src = n, t.async = !0, t.onload = function() {
  361. return e()
  362. }, t.onerror = function() {
  363. var e = "file not found: " + n;
  364. if (!i) throw e;
  365. o(e)
  366. }, document.head.appendChild(t)
  367. })
  368. }
  369. window.onerror = function() {
  370. Module.setStatus("Exception thrown, see JavaScript console"), Module.setStatus = function(e) {
  371. e && Module.printErr("[post-exception status] " + e)
  372. }
  373. }, window.addEventListener("message", onMessage, !1), void 0 !== document.hidden ? (hidden = "hidden", visibilityChange = "visibilitychange") : void 0 !== document.msHidden ? (hidden = "msHidden", visibilityChange = "msvisibilitychange") : void 0 !== document.webkitHidden && (hidden = "webkitHidden", visibilityChange = "webkitvisibilitychange"), void 0 === document.addEventListener || void 0 === document.hidden ? console.log("error: no support for Page Visibility API.") : document.addEventListener(visibilityChange, handleVisibilityFocusChange, !1), window.addEventListener("focus", handleVisibilityFocusChange), window.addEventListener("blur", handleVisibilityFocusChange), window.notify = {
  374. list: [],
  375. id: 0,
  376. compatible: function() {
  377. return "undefined" != typeof Notification
  378. },
  379. authorize: function() {
  380. notify.compatible() && Notification.requestPermission(function(e) {
  381. LocalNotify = "granted" == e
  382. })
  383. },
  384. show: function(e, o) {
  385. if (LocalNotify) {
  386. notify.id++;
  387. var t = notify.id;
  388. notify.list[t] = new Notification(e, {
  389. body: o,
  390. tag: t,
  391. icon: "https://xat.com/images/planet.svg",
  392. lang: "",
  393. dir: "auto"
  394. }), notify.logEvent("Notification #" + t + " queued for display"), notify.list[t].onclick = function() {
  395. notify.logEvent(t, "clicked")
  396. }, notify.list[t].onshow = function() {
  397. notify.logEvent(t, "showed")
  398. }, notify.list[t].onerror = function() {
  399. notify.logEvent(t, "errored")
  400. }, notify.list[t].onclose = function() {
  401. notify.logEvent(t, "closed")
  402. }, console.log("Created a new notification ..."), console.log(notify.list[t])
  403. }
  404. },
  405. logEvent: function(e, o) {}
  406. };
  407. var userbrowser, browsers = ["Chrome", "Edge", "Firefox", "Safari", "OPR", "MSIE", "Trident"],
  408. useragent = navigator.userAgent;
  409. for (i = 0; i < browsers.length; i++)
  410. if (-1 < useragent.indexOf(browsers[i])) {
  411. userbrowser = browsers[i];
  412. break
  413. }
  414. switch (userbrowser) {
  415. case "Chrome":
  416. case "Firefox":
  417. case "OPR":
  418. loadJsModule("www/firebase.js")
  419. }
  420. loadJsModule("www/howler.js"), window.WebAssembly ? loadJsModule("xatcorewasm.php", 1).then(function(e) {}, function(e) {
  421. loadJsModule("xatcore.php")
  422. }) : loadJsModule("xatcore.php");
Add Comment
Please, Sign In to add comment