Skip to content

Instantly share code, notes, and snippets.

@gollilla
Created November 19, 2019 04:32
Show Gist options
  • Save gollilla/71fe027c862a1a8dcf9e5644eb4838ad to your computer and use it in GitHub Desktop.
Save gollilla/71fe027c862a1a8dcf9e5644eb4838ad to your computer and use it in GitHub Desktop.
<html>
<head>
<title>TEST</title>
</head>
<body>
<div id="editor" style="height: 600px" oninput="input(this)" onkeyup="input(this)"></div>
<script>
function GetQueryString() {
var result = {};
if (1 < window.location.search.length) {
// 最初の1文字 (?記号) を除いた文字列を取得する
var query = window.location.search.substring(1);
// クエリの区切り記号 (&) で文字列を配列に分割する
var parameters = query.split('&');
for (var i = 0; i < parameters.length; i++) {
// パラメータ名とパラメータ値に分割する
var element = parameters[i].split('=');
var paramName = decodeURIComponent(element[0]);
var paramValue = decodeURIComponent(element[1]);
// パラメータ名をキーとして連想配列に追加する
result[paramName] = paramValue;
}
}
return result;
}
var room_id = GetQueryString()["id"]
var conn = new WebSocket('ws://localhost:8080/?id=' + room_id);
conn.onopen = function (e) {
console.log("Connection established!");
};
</script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.0/ext-language_tools.js"></script>
<script>
var editor = ace.edit("editor");
editor.$blockScrolling = Infinity;
editor.setOptions({
enableBasicAutocompletion: true,
enableSnippets: true,
enableLiveAutocompletion: true
});
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/php");
editor.setFontSize(20);
</script>
<script>
function input(){
var text = editor.getValue();
conn.send(text);
}
conn.onmessage = function (e) {
editor.setValue(e.data);
};
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment