Advertisement
salahzar

chat.js ctrlaltstudio

Jul 31st, 2018
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*!
  2. chat.js
  3.  
  4. Created by David Rowe on 20 Jul 2015.
  5. Copyright 2015 David Rowe.
  6.  
  7. Information: http://ctrlaltstudio.com/hifi/chat
  8.  
  9. License: http://ctrlaltstudio.com/hifi/chat/license
  10. */
  11. function a() {
  12.     function d(t) {
  13.         n.setVisible(t);
  14.         t && (n.raise(), v = Date.now());
  15.         u = t
  16.     }
  17.  
  18.     function g() {
  19.         return u && Date.now() - v < k
  20.     }
  21.  
  22.     function nt(t) {
  23.         n.setTitle(t)
  24.     }
  25.  
  26.     function tt(t) {
  27.         n.emitScriptEvent(JSON.stringify({
  28.             type: "messages",
  29.             messages: t
  30.         }))
  31.     }
  32.  
  33.     function it(t, i) {
  34.         n.emitScriptEvent(JSON.stringify({
  35.             type: "message",
  36.             user: t,
  37.             message: i
  38.         }))
  39.     }
  40.  
  41.     function rt() {
  42.         n.emitScriptEvent(JSON.stringify({
  43.             type: "clear"
  44.         }))
  45.     }
  46.  
  47.     function ut() {
  48.         var t, i;
  49.         t = Settings.getValue(HMD.active ? c : h);
  50.         HMD.active && t === "" && (t = p);
  51.         i = Settings.getValue(HMD.active ? s : o);
  52.         i === "" && (i = {
  53.             width: l,
  54.             height: a
  55.         });
  56.         t !== "" && n.setPosition(t)
  57.     }
  58.  
  59.     function b(n) {
  60.         var t = JSON.parse(n);
  61.         t.type === "message" ? y(t.message) : t.type === "close" ? g() || e() : t.type === "loaded" && f !== null && f()
  62.     }
  63.  
  64.     function ft(n) {
  65.         i !== undefined && Script.clearTimeout(i);
  66.         i = Script.setTimeout(function() {
  67.             Settings.setValue(HMD.active ? s : o, n);
  68.             i = undefined
  69.         }, w)
  70.     }
  71.  
  72.     function et(n) {
  73.         u && (r !== undefined && Script.clearTimeout(r), t = n, r = Script.setTimeout(function() {
  74.             Settings.setValue(HMD.active ? c : h, t);
  75.             r = undefined
  76.         }, w))
  77.     }
  78.  
  79.     function ot() {
  80.         e()
  81.     }
  82.  
  83.     function st(i, r, u, v) {
  84.         var k, w;
  85.         k = Script.resolvePath("html/chat.html");
  86.         w = Settings.getValue(HMD.active ? s : o);
  87.         w === "" && (w = {
  88.             width: l,
  89.             height: a
  90.         });
  91.         t = Settings.getValue(HMD.active ? c : h);
  92.         f = r;
  93.         y = u;
  94.         e = v;
  95.         n = new OverlayWebWindow(i, k, w.width, w.height, !1);
  96.         HMD.active && t === "" && (t = p);
  97.         t !== "" && n.setPosition(t);
  98.         n.setVisible(!1);
  99.         n.webEventReceived.connect(b);
  100.         n.moved.connect(et);
  101.         n.resized.connect(ft);
  102.         n.closed.connect(ot)
  103.     }
  104.  
  105.     function ht() {
  106.         n.webEventReceived.disconnect(b)
  107.     }
  108.     var n, l = 400,
  109.         a = 600,
  110.         t, u = !1,
  111.         v, k = 1e3,
  112.         f, y, e, o = "Chat Window Size Desktop",
  113.         s = "Chat Window Size",
  114.         h = "Chat Window Position Desktop",
  115.         c = "Chat Window Position",
  116.         p = {
  117.             x: 2e3,
  118.             y: 200
  119.         },
  120.         i, r, w = 500;
  121.     return {
  122.         z1: d,
  123.         z2: nt,
  124.         z3: ut,
  125.         z4: tt,
  126.         z5: it,
  127.         z6: rt,
  128.         za: st,
  129.         zb: ht
  130.     }
  131. }
  132. var o = function() {
  133.     function c() {
  134.         return "Local Chat @ " + Window.location.hostname + (i ? "" : " (NOT CONNECTED)")
  135.     }
  136.  
  137.     function l() {
  138.         Script.setTimeout(function() {
  139.             var t;
  140.             h || (t = c(), n.z2(t))
  141.         }, 1e3)
  142.     }
  143.  
  144.     function r(i) {
  145.         i !== f && (Menu.setIsOptionChecked(t, i), i ? n.z4(e) : n.z6(), n.z1(i), f = i)
  146.     }
  147.  
  148.     function v(n) {
  149.         n === t && r(Menu.isOptionChecked(t))
  150.     }
  151.  
  152.     function g() {
  153.         r(!1)
  154.     }
  155.  
  156.     function y(n) {
  157.         if (n.key === s) {
  158.             r(!Menu.isOptionChecked(t));
  159.             return
  160.         }
  161.     }
  162.  
  163.     function nt(t, i) {
  164.         e[e.length] = {
  165.             user: t,
  166.             message: i
  167.         };
  168.         f && n.z5(t, i)
  169.     }
  170.  
  171.     function p(n, t, i) {
  172.         var r;
  173.         n === u && (r = AvatarManager.getAvatar(i).displayName, nt(r, t))
  174.     }
  175.  
  176.     function tt(n) {
  177.         Messages.sendMessage(u, n)
  178.     }
  179.  
  180.     function w() {
  181.         l();
  182.         n.z6()
  183.     }
  184.  
  185.     function it() {
  186.         n.z3()
  187.     }
  188.  
  189.     function b() {
  190.         i !== Window.location.isConnected && (i = !i, l())
  191.     }
  192.  
  193.     function rt() {
  194.         n = a();
  195.         Window.location.hostChanged.connect(w);
  196.         i = Window.location.isConnected;
  197.         n.za(c(), null, tt, g);
  198.         Menu.addMenuItem({
  199.             menuName: o,
  200.             menuItemName: t,
  201.             afterItem: k,
  202.             shortcutKey: d,
  203.             isCheckable: !0
  204.         });
  205.         Menu.menuItemEvent.connect(v);
  206.         HMD.displayModeChanged.connect(it);
  207.         Messages.subscribe(u);
  208.         Messages.messageReceived.connect(p);
  209.         Controller.captureKeyEvents({
  210.             key: s
  211.         });
  212.         Controller.keyPressEvent.connect(y);
  213.         r(Menu.isOptionChecked(t));
  214.         Script.update.connect(b)
  215.     }
  216.  
  217.     function ut() {
  218.         h = !0;
  219.         r(!1);
  220.         Script.update.disconnect(b);
  221.         Controller.keyPressEvent.disconnect(y);
  222.         Messages.unsubscribe(u);
  223.         Messages.messageReceived.disconnect(p);
  224.         Menu.menuItemEvent.disconnect(v);
  225.         Window.location.hostChanged.disconnect(w);
  226.         n.zb();
  227.         Menu.removeMenuItem(o, t)
  228.     }
  229.     var n, f = !1,
  230.         i, o = "View",
  231.         t = "Local Chat...",
  232.         k = "Mini Mirror",
  233.         d = "\\",
  234.         s = 92,
  235.         u = "chat",
  236.         e = [],
  237.         h = !1;
  238.     rt();
  239.     Script.scriptEnding.connect(ut)
  240. }()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement