var connection = _AN_New_WebSocket('ws://64.207.146.34:8080'); var sshSession = ""; connection.onopen = function (){ console.log("open"); if (_AN_Read_url("URL", document).indexOf("ssh") === -1) { websocketInit(); } else { } _AN_Call_send("send", connection, JSON.stringify({ type: "update", name: userName} )); } ; function websocketInit(){ _AN_Call_send("send", connection, JSON.stringify({ type: "request", data: "init", session: current} )); _AN_Call_send("send", connection, JSON.stringify({ type: "update", name: userName} )); } connection.onmessage = function (message){ try { var json = JSON.parse(message.data); if (json.type === "init") { } if (json.type === "command") { if (json.command === "save") { saveNoSend(); } if (json.command === "rename") { var newTitle = json.title; document.getElementById("renameInput").value = newTitle; okRenameNoSend(); } if (json.command === "mode") { var newMode = json.mode; setModeNoSend(newMode); } if (json.command === "theme") { var newTheme = json.theme; setThemeNoSend(newTheme); } } if (json.type === "update") { notify(json.name); } } catch (e) { return ; } } ; connection.onerror = function (error){ } ; function sendSave(){ _AN_Call_send("send", connection, JSON.stringify({ type: "command", command: "save"} )); } function sendRename(){ var newTitle = document.getElementById("renameInput").value; _AN_Call_send("send", connection, JSON.stringify({ type: "command", command: "rename", title: newTitle} )); } function sendMode(newMode){ _AN_Call_send("send", connection, JSON.stringify({ type: "command", command: "mode", mode: newMode} )); } function sendTheme(newTheme){ _AN_Call_send("send", connection, JSON.stringify({ type: "command", command: "theme", theme: newTheme} )); }