Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.86 KB | None | 0 0
  1. <html>
  2. <head>
  3. <title>Toiney Chat Client</title>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <meta name="description" content="">
  8. <meta name="author" content="">
  9. <link rel="shortcut icon" href="favicon.ico">
  10. <!-- will's pimpin css imports -->
  11. <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-9gVQ4dYFwwWSjIDZnLEWnxCjeSWFphJiwGPXr1jddIhOegiu1FwO5qRGvFXOdJZ4" crossorigin="anonymous">
  12. <link href="https://stackpath.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
  13. <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>
  14.  
  15. <script src="http://code.jquery.com/jquery-1.10.1.min.js"></script>
  16. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
  17. <style>
  18. body{
  19. background:#252830;
  20. margin:0px;
  21. height:900px;
  22. color:#cfd2da;
  23. font-family: sans-serif;
  24. height:100%;
  25. width:100%;
  26. margin-left:1%;
  27. background-image: url(http://fjordstudio.dk/assets/img/bg/diamonds.png);
  28.  
  29. }
  30. .rainbow {
  31. /* Chrome, Safari, Opera */
  32. -webkit-animation: rainbow 3s infinite;
  33.  
  34. /* Internet Explorer */
  35. -ms-animation: rainbow 3s infinite;
  36.  
  37. /* Standar Syntax */
  38. animation: rainbow 3s infinite;
  39. }
  40.  
  41. /* Chrome, Safari, Opera */
  42. @-webkit-keyframes rainbow{
  43. 20%{color: red;}
  44. 40%{color: yellow;}
  45. 60%{color: green;}
  46. 80%{color: blue;}
  47. 100%{color: orange;}
  48. }
  49. /* Internet Explorer */
  50. @-ms-keyframes rainbow{
  51. 20%{color: red;}
  52. 40%{color: yellow;}
  53. 60%{color: green;}
  54. 80%{color: blue;}
  55. 100%{color: orange;}
  56. }
  57.  
  58. /* Standar Syntax */
  59. @keyframes rainbow{
  60. 5%{color: red;}
  61. 35%{color: yellow;}
  62. 65%{color: green;}
  63. 85%{color: blue;}
  64. 0%{color: orange;}
  65. }
  66. btn{
  67. color:#cfd2da;
  68. }
  69. h1,p,h2,h3{
  70. color:#cfd2da;
  71. }
  72. .chat_box{
  73. position:fixed;
  74. right:20px;
  75. bottom:0px;
  76. width:250px;
  77. }
  78. .chat_body{
  79. background:white;
  80. height:400px;
  81. padding:5px 0px;
  82. }
  83.  
  84. .chat_head,.msg_head{
  85. background:#f39c12;
  86. color:white;
  87. padding:15px;
  88. font-weight:bold;
  89. cursor:pointer;
  90. border-radius:5px 5px 0px 0px;
  91. }
  92.  
  93. .msg_box{
  94. position:fixed;
  95. bottom:-5px;
  96. width:250px;
  97. background:white;
  98. border-radius:5px 5px 0px 0px;
  99. }
  100.  
  101. .msg_head{
  102. background:#3498db;
  103. }
  104.  
  105. .msg_body{
  106. background:white;
  107. height:200px;
  108. font-size:12px;
  109. padding:15px;
  110. overflow:auto;
  111. overflow-x: hidden;
  112. }
  113. .msg_input{
  114. width:100%;
  115. border: 1px solid white;
  116. border-top:1px solid #DDDDDD;
  117. -webkit-box-sizing: border-box; /* Safari/Chrome, other WebKit */
  118. -moz-box-sizing: border-box; /* Firefox, other Gecko */
  119. box-sizing: border-box;
  120. }
  121.  
  122. .close{
  123. float:right;
  124. cursor:pointer;
  125. }
  126. .minimize{
  127. float:right;
  128. cursor:pointer;
  129. padding-right:5px;
  130.  
  131. }
  132.  
  133. .user{
  134. position:relative;
  135. padding:10px 30px;
  136. }
  137. .user:hover{
  138. background:#f8f8f8;
  139. cursor:pointer;
  140.  
  141. }
  142. .user:before{
  143. content:'';
  144. position:absolute;
  145. background:#2ecc71;
  146. height:10px;
  147. width:10px;
  148. left:10px;
  149. top:15px;
  150. border-radius:6px;
  151. }
  152.  
  153. .msg_a{
  154. position:relative;
  155. background:#FDE4CE;
  156. padding:10px;
  157. min-height:10px;
  158. margin-bottom:5px;
  159. margin-right:10px;
  160. border-radius:5px;
  161. }
  162. .msg_a:before{
  163. content:"";
  164. position:absolute;
  165. width:0px;
  166. height:0px;
  167. border: 10px solid;
  168. border-color: transparent #FDE4CE transparent transparent;
  169. left:-20px;
  170. top:7px;
  171. }
  172.  
  173.  
  174. .msg_b{
  175. background:#EEF2E7;
  176. padding:10px;
  177. min-height:15px;
  178. margin-bottom:5px;
  179. position:relative;
  180. margin-left:10px;
  181. border-radius:5px;
  182. word-wrap: break-word;
  183. }
  184. .msg_b:after{
  185. content:"";
  186. position:absolute;
  187. width:0px;
  188. height:0px;
  189. border: 10px solid;
  190. border-color: transparent transparent transparent #EEF2E7;
  191. right:-20px;
  192. top:7px;
  193. }
  194. /* Dropdown Button */
  195. .dropbtn {
  196. background-color: #3498DB;
  197. color: white;
  198. padding: 16px;
  199. font-size: 16px;
  200. border: none;
  201. cursor: pointer;
  202. }
  203.  
  204. /* Dropdown button on hover & focus */
  205. .dropbtn:hover, .dropbtn:focus {
  206. background-color: #2980B9;
  207. }
  208.  
  209. /* The container <div> - needed to position the dropdown content */
  210. .dropdown {
  211. position: relative;
  212. display: inline-block;
  213. }
  214.  
  215. /* Dropdown Content (Hidden by Default) */
  216. .dropdown-content {
  217. display: none;
  218. position: absolute;
  219. background-color: #f1f1f1;
  220. min-width: 160px;
  221. box-shadow: 0px 8px 16px 0px rgba(0,0,0,0.2);
  222. z-index: 1;
  223. }
  224.  
  225. /* Links inside the dropdown */
  226. .dropdown-content a {
  227. color: black;
  228. padding: 12px 16px;
  229. text-decoration: none;
  230. display: block;
  231. }
  232.  
  233. /* Change color of dropdown links on hover */
  234. .dropdown-content a:hover {background-color: #ddd}
  235.  
  236. /* Show the dropdown menu (use JS to add this class to the .dropdown-content container when the user clicks on the dropdown button) */
  237. .show {display:block;}
  238. </style>
  239.  
  240. </head>
  241. <body>
  242. <h1>Toiney <span class="rainbow">Pimpin'</span> Chat Client</h1>
  243. <p>
  244. Host: <input id="webSocketHost" class="form-control" style="width:25%" type="text" value="www.teenchat.com/ws"/>
  245. </p>
  246. <p>
  247. <button class="btn btn-success" onClick="initWebSocket();">Connect</button>
  248. <button class="btn btn-danger" id="disconnectButton" onClick="stopWebSocket();" disabled>Disconnect</button>
  249. <button class="btn btn-warning" onClick="checkSocket();">State</button>
  250. <button class="btn btn-primary" id ="reqBtn" onClick="req_list({{ data }});">Send Requirements</button>
  251. </p>
  252. <p>
  253. <textarea id="debugTextArea" class="form-control" rows="3" style="width:40%" readonly></textarea>
  254. </p>
  255. <p>
  256. <textarea id="chatTextArea" class="form-control" style="width:40%;" readonly></textarea>
  257. </p>
  258. <p>
  259. <input type="text" id="inputText" class="form-control" style="width:40%;" onkeydown="if(event.keyCode===13)sendMessage();"/>
  260. <button id="sendButton" class="btn btn-success" onClick="sendMessage();" disabled>Send</button>
  261. </p>
  262. <div class="dropdown">
  263. <button class="btn btn-secondary dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
  264. User
  265. </button>
  266. <div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
  267. <a class="dropdown-item" href="#">Action</a>
  268. <a class="dropdown-item" href="#">Another action</a>
  269. <a class="dropdown-item" href="#">Something else here</a>
  270. </div>
  271. </div>
  272.  
  273.  
  274. <script type="text/javascript">
  275. var debugTextArea = document.getElementById("debugTextArea");
  276. var chatTextArea = document.getElementById("chatTextArea");
  277.  
  278. function debug(message) {
  279. debugTextArea.value += message + "\n";
  280. debugTextArea.scrollTop = debugTextArea.scrollHeight;
  281. }
  282.  
  283. function format(msg) {
  284. chatTextArea.value += msg + "\n";
  285. chatTextArea.scrollTop = chatTextArea.scrollHeight;
  286. }
  287.  
  288. function sendMessage() {
  289. var strToSend = document.getElementById("inputText").value;
  290. if ( websocket != null) {
  291. if (strToSend === '!main') {
  292. strToSend.replace("!main", "");
  293. document.getElementById("inputText").value = "";
  294. websocket.send( '{"Post": "' + 'lol' + '", "RoomID": "rdqlcurrmpk", "C": "post"}' );
  295. console.log( "string sent :", '"'+strToSend+'"' );
  296. format(strToSend);
  297. } else {
  298. document.getElementById("inputText").value = "";
  299. websocket.send(strToSend);
  300. console.log("string sent :", '"' + strToSend + '"');
  301. debug(strToSend);
  302. }
  303. }
  304. }
  305.  
  306. var websocket = null;
  307.  
  308. function initWebSocket() {
  309. try {
  310. if (typeof MozWebSocket === 'function')
  311. WebSocket = MozWebSocket;
  312. if ( websocket && websocket.readyState === 1 )
  313. websocket.close();
  314. var wsUri = "ws://" + document.getElementById("webSocketHost").value;
  315. websocket = new WebSocket( wsUri );
  316. websocket.onopen = function (evt) {
  317. debug("CONNECTED");
  318. document.getElementById("disconnectButton").disabled = false;
  319. document.getElementById("sendButton").disabled = false;
  320. document.getElementById("reqBtn").disabled = false;
  321. };
  322. websocket.onclose = function (evt) {
  323. debug("DISCONNECTED");
  324. document.getElementById("disconnectButton").disabled = true;
  325. document.getElementById("sendButton").disabled = true;
  326. document.getElementById("reqBtn").disabled = true;
  327. };
  328. websocket.onmessage = function (evt) {
  329. console.log( "Message received :", evt.data );
  330. debug( evt.data );
  331. // resp will be sent to format textbox
  332. var resp = JSON.parse(evt.data);
  333. if (resp !== undefined) {
  334. var options = [
  335. set0 = [resp['UID']]
  336. ];
  337.  
  338. function makeUL(array) {
  339. // Create the list element:
  340. var list = document.createElement('ul');
  341.  
  342. for(var i = 0; i < array.length; i++) {
  343. // Create the list item:
  344. var item = document.createElement('li');
  345. item.setAttribute("id", resp['UID']);
  346. // Set its contents:
  347. item.appendChild(document.createTextNode(array[i]));
  348.  
  349. // Add it to the list:
  350. list.appendChild(item);
  351. }
  352.  
  353. // Finally, return the constructed list:
  354. return list;
  355. }
  356.  
  357. // Add the contents of options[0] to #myDropdown:
  358. document.getElementById('chatTabs').appendChild(makeUL(options[0]));
  359. }
  360. else {
  361. format("unlucky")
  362. }
  363. };
  364. websocket.onerror = function (evt) {
  365. debug('ERROR: ' + evt.data);
  366. };
  367. } catch (exception) {
  368. debug('ERROR: ' + exception);
  369. }
  370. }
  371.  
  372. function req_list(data) {
  373. if (websocket != null) {
  374. debug("Sending REQ LIST");
  375. setTimeout(function () {
  376. arrayLength = data.length;
  377. for (var i = 0; i < arrayLength; i++) {
  378. websocket.send(data[i]);
  379. }
  380. }, 1000)
  381. }
  382. }
  383.  
  384. function stopWebSocket() {
  385. if (websocket)
  386. websocket.close();
  387. }
  388.  
  389. function checkSocket() {
  390. if (websocket != null) {
  391. var stateStr;
  392. switch (websocket.readyState) {
  393. case 0: {
  394. stateStr = "CONNECTING";
  395. break;
  396. }
  397. case 1: {
  398. stateStr = "OPEN";
  399. break;
  400. }
  401. case 2: {
  402. stateStr = "CLOSING";
  403. break;
  404. }
  405. case 3: {
  406. stateStr = "CLOSED";
  407. break;
  408. }
  409. default: {
  410. stateStr = "UNKNOWN";
  411. break;
  412. }
  413. }
  414. debug("WebSocket state = " + websocket.readyState + " ( " + stateStr + " )");
  415. } else {
  416. debug("WebSocket is null");
  417. }
  418. }
  419. /* When the user clicks on the button,
  420. toggle between hiding and showing the dropdown content */
  421. function myFunction() {
  422. document.getElementById("myDropdown").classList.toggle("show");
  423. }
  424.  
  425. // Close the dropdown menu if the user clicks outside of it
  426. window.onclick = function(event) {
  427. if (!event.target.matches('.dropbtn')) {
  428.  
  429. var dropdowns = document.getElementsByClassName("dropdown-content");
  430. var i;
  431. for (i = 0; i < dropdowns.length; i++) {
  432. var openDropdown = dropdowns[i];
  433. if (openDropdown.classList.contains('show')) {
  434. openDropdown.classList.remove('show');
  435. }
  436. }
  437. }
  438. }
  439. $(document).ready(function(){
  440.  
  441. $('.chat_head').click(function(){
  442. $('.chat_body').slideToggle('slow');
  443. });
  444. $('.msg_head').click(function(){
  445. $('.msg_wrap').slideToggle('slow');
  446. });
  447.  
  448. $('.close').click(function(){
  449. $('.msg_box').hide();
  450. });
  451.  
  452. $('.user').click(function(){
  453.  
  454. $('.msg_wrap').show();
  455. $('.msg_box').show();
  456. });
  457.  
  458. $('textarea').keypress(
  459. function(e){
  460. if (e.keyCode == 13) {
  461. e.preventDefault();
  462. var msg = $(this).val();
  463. $(this).val('');
  464. if(msg!='')
  465. $('<div class="msg_b">'+msg+'</div>').insertBefore('.msg_push');
  466. $('.msg_body').scrollTop($('.msg_body')[0].scrollHeight);
  467. }
  468. });
  469.  
  470. });
  471. </script>
  472.  
  473. <div class="chat_box">
  474. <div class="chat_head"> Chat Box</div>
  475. <div class="chat_body">
  476. <div id="chatTabs"></div>
  477. </div>
  478. </div>
  479.  
  480. <div class="msg_box" style="right:290px">
  481. <div class="msg_head">
  482. <div class="close">x</div>
  483. </div>
  484. <div class="msg_wrap">
  485. <div class="msg_body">
  486. <div class="msg_b" id="msgBody"></div>
  487. <div class="msg_push"></div>
  488. </div>
  489. <div class="msg_footer"><textarea class="msg_input" rows="4"></textarea></div>
  490. </div>
  491.  
  492. </div>
  493. </body>
  494. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement