Advertisement
crypt404

Untitled

Feb 22nd, 2024
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. /* -----------------------------------------------
  2. /* How to use? : Check the GitHub README
  3. /* ----------------------------------------------- */
  4.  
  5. /* To load a config file (particles.json) you need to host this demo (MAMP/WAMP/local)... */
  6. /*
  7. particlesJS.load('particles-js', 'particles.json', function() {
  8. console.log('particles.js loaded - callback');
  9. });
  10. */
  11.  
  12. /* Otherwise just put the config content (json): */
  13. // @ts-nocheck
  14.  
  15. const johnSelectorBtn = document.querySelector('#john-selector')
  16. const janeSelectorBtn = document.querySelector('#jane-selector')
  17. const chatHeader = document.querySelector('.chat-header')
  18. const chatMessages = document.querySelector('.chat-messages')
  19. const chatInputForm = document.querySelector('.chat-input-form')
  20. const chatInput = document.querySelector('.chat-input')
  21. const clearChatBtn = document.querySelector('.clear-chat-button')
  22.  
  23. const messages = JSON.parse(localStorage.getItem('messages')) || []
  24.  
  25. const createChatMessageElement = (message) => `
  26. <div class="message ${message.sender === 'John' ? 'blue-bg' : 'gray-bg'}">
  27. <div class="message-sender">${message.sender}</div>
  28. <div class="message-text">${message.text}</div>
  29. <div class="message-timestamp">${message.timestamp}</div>
  30. </div>
  31. `
  32.  
  33. window.onload = () => {
  34. messages.forEach((message) => {
  35. chatMessages.innerHTML += createChatMessageElement(message)
  36. })
  37. }
  38.  
  39. let messageSender = 'John'
  40.  
  41. const updateMessageSender = (name) => {
  42. messageSender = name
  43. chatHeader.innerText = `${messageSender} chatting...`
  44. chatInput.placeholder = `Type here, ${messageSender}...`
  45.  
  46. if (name === 'John') {
  47. johnSelectorBtn.classList.add('active-person')
  48. janeSelectorBtn.classList.remove('active-person')
  49. }
  50. if (name === 'Jane') {
  51. janeSelectorBtn.classList.add('active-person')
  52. johnSelectorBtn.classList.remove('active-person')
  53. }
  54.  
  55. /* auto-focus the input field */
  56. chatInput.focus()
  57. }
  58.  
  59. johnSelectorBtn.onclick = () => updateMessageSender('John')
  60. janeSelectorBtn.onclick = () => updateMessageSender('Jane')
  61.  
  62. const sendMessage = (e) => {
  63. e.preventDefault()
  64.  
  65. const timestamp = new Date().toLocaleString('en-US', { hour: 'numeric', minute: 'numeric', hour12: true })
  66. const message = {
  67. sender: messageSender,
  68. text: chatInput.value,
  69. timestamp,
  70. }
  71.  
  72. /* Save message to local storage */
  73. messages.push(message)
  74. localStorage.setItem('messages', JSON.stringify(messages))
  75.  
  76. /* Add message to DOM */
  77. chatMessages.innerHTML += createChatMessageElement(message)
  78.  
  79. /* Clear input field */
  80. chatInputForm.reset()
  81.  
  82. /* Scroll to bottom of chat messages */
  83. chatMessages.scrollTop = chatMessages.scrollHeight
  84. }
  85.  
  86. chatInputForm.addEventListener('submit', sendMessage)
  87.  
  88. clearChatBtn.addEventListener('click', () => {
  89. localStorage.clear()
  90. chatMessages.innerHTML = ''
  91. })
  92.  
  93. particlesJS('particles-js',
  94.  
  95. {
  96. "particles": {
  97. "number": {
  98. "value": 80,
  99. "density": {
  100. "enable": true,
  101. "value_area": 800
  102. }
  103. },
  104. "color": {
  105. "value": "#ffffff"
  106. },
  107. "shape": {
  108. "type": "circle",
  109. "stroke": {
  110. "width": 0,
  111. "color": "#000000"
  112. },
  113. "polygon": {
  114. "nb_sides": 5
  115. },
  116. "image": {
  117. "src": "img/github.svg",
  118. "width": 100,
  119. "height": 100
  120. }
  121. },
  122. "opacity": {
  123. "value": 0.5,
  124. "random": false,
  125. "anim": {
  126. "enable": false,
  127. "speed": 1,
  128. "opacity_min": 0.1,
  129. "sync": false
  130. }
  131. },
  132. "size": {
  133. "value": 5,
  134. "random": true,
  135. "anim": {
  136. "enable": false,
  137. "speed": 40,
  138. "size_min": 0.1,
  139. "sync": false
  140. }
  141. },
  142. "line_linked": {
  143. "enable": true,
  144. "distance": 150,
  145. "color": "#ffffff",
  146. "opacity": 0.4,
  147. "width": 1
  148. },
  149. "move": {
  150. "enable": true,
  151. "speed": 6,
  152. "direction": "none",
  153. "random": false,
  154. "straight": false,
  155. "out_mode": "out",
  156. "attract": {
  157. "enable": false,
  158. "rotateX": 600,
  159. "rotateY": 1200
  160. }
  161. }
  162. },
  163. "interactivity": {
  164. "detect_on": "canvas",
  165. "events": {
  166. "onhover": {
  167. "enable": true,
  168. "mode": "repulse"
  169. },
  170. "onclick": {
  171. "enable": true,
  172. "mode": "push"
  173. },
  174. "resize": true
  175. },
  176. "modes": {
  177. "grab": {
  178. "distance": 400,
  179. "line_linked": {
  180. "opacity": 1
  181. }
  182. },
  183. "bubble": {
  184. "distance": 400,
  185. "size": 40,
  186. "duration": 2,
  187. "opacity": 8,
  188. "speed": 3
  189. },
  190. "repulse": {
  191. "distance": 200
  192. },
  193. "push": {
  194. "particles_nb": 4
  195. },
  196. "remove": {
  197. "particles_nb": 2
  198. }
  199. }
  200. },
  201. "retina_detect": true,
  202. "config_demo": {
  203. "hide_card": false,
  204. "background_color": "#b61924",
  205. "background_image": "",
  206. "background_position": "50% 50%",
  207. "background_repeat": "no-repeat",
  208. "background_size": "cover"
  209. }
  210. }
  211.  
  212. );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement