index.html 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. <!DOCTYPE html>
  2. <html lang="it">
  3. <head>
  4. <meta charset="UTF-8" />
  5. <title>HOD8</title>
  6. <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
  7. <style>
  8. body {
  9. box-sizing: border-box;
  10. margin: 0;
  11. padding: 0;
  12. padding-bottom: 3rem;
  13. font-family: "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  14. overflow: hidden;
  15. width: 100vw;
  16. }
  17. iframe {
  18. width: 100%;
  19. height: 50vh;
  20. }
  21. #form {
  22. background: rgba(0, 0, 0, 0.15);
  23. padding: 0.25rem;
  24. position: absolute;
  25. bottom: 0;
  26. left: 0;
  27. right: 0;
  28. display: flex;
  29. height: 8vh;
  30. box-sizing: border-box;
  31. justify-content: center;
  32. }
  33. #username {
  34. font-size: small;
  35. margin: 0;
  36. padding: 0;
  37. text-align: center;
  38. }
  39. #username a {
  40. padding: 0;
  41. margin: 0;
  42. }
  43. #input {
  44. border: none;
  45. padding: 0 1rem;
  46. flex-grow: 1;
  47. border-radius: 2rem;
  48. margin: 0.25rem;
  49. }
  50. #input:focus {
  51. outline: none;
  52. }
  53. #form>button {
  54. background: #333;
  55. border: none;
  56. padding: 0 1rem;
  57. margin: 0.25rem;
  58. border-radius: 3px;
  59. outline: none;
  60. color: #fff;
  61. }
  62. #messages {
  63. list-style-type: none;
  64. width: 98%;
  65. margin: 0 auto;
  66. padding: 0px;
  67. background: #eee;
  68. border-radius: 5px;
  69. overflow-y: scroll;
  70. max-height: 20vh;
  71. }
  72. #messages>li {
  73. padding: 0.5rem 1rem;
  74. border-bottom: 1px solid black;
  75. }
  76. #messages>li:nth-child(odd) {
  77. background: #efefef;
  78. }
  79. h1 {
  80. text-align: center;
  81. padding: 0;
  82. margin-top: 5px;
  83. margin-bottom: 5px;
  84. }
  85. #chat #title {
  86. text-align: center;
  87. }
  88. </style>
  89. </head>
  90. <body>
  91. <h1>Hack or Di(Y|E) 8</h1>
  92. <div id="username">
  93. <p>Tu sei: <a href="" id="value"></a></p>
  94. </div>
  95. <!--<iframe allowfullscreen="true" src="https://file-examples.com/storage/fe8c7eef0c6364f6c9504cc/2017/04/file_example_MP4_480_1_5MG.mp4" frameborder="0"></iframe>-->
  96. <iframe allowfullscreen="true" src="https://hod8.vado.li/" frameborder="0"></iframe>
  97. <div id="chat">
  98. <div id="title">Chat</div>
  99. <ul id="messages"></ul>
  100. </div>
  101. <form id="form" action="">
  102. <input placeholder='Scrivi il messaggio' type='text' id="input" autocomplete="off" /><button>Invia</button>
  103. </form>
  104. <script src="/socket.io/socket.io.js"></script>
  105. <script>
  106. function replaceURLWithHTMLLinks(text) {
  107. var exp = /(\b(http|ftp|https):\/\/([\w-]+\.[\w-]+)+([\w.,@?^=%&amp;:\/~+#-]*[\w@?^=%&amp;\/~+#-])?)/ig;
  108. return text.replace(exp, "<a href='$1'>$1</a>");
  109. }
  110. var username = '';
  111. var socket = io();
  112. var form = document.getElementById('form');
  113. var input = document.getElementById('input');
  114. form.addEventListener('submit', function (e) {
  115. e.preventDefault();
  116. if (input.value) {
  117. socket.emit('chat message', input.value);
  118. input.value = '';
  119. }
  120. });
  121. socket.on('chat message', function (msg) {
  122. var item = document.createElement('li');
  123. // console.log(username);
  124. item.innerHTML = replaceURLWithHTMLLinks(`${msg}`);
  125. messages.appendChild(item).scrollIntoView({ behavior: "smooth", block: "end", inline: "nearest" });
  126. });
  127. socket.on('username', function (msg) {
  128. let domUsername = document.querySelector('#value');
  129. domUsername.textContent = msg.split('@@@')[0];
  130. domUsername.setAttribute('href', msg.split('@@@')[1]);
  131. username = msg;
  132. });
  133. </script>
  134. </body>
  135. </html>