ivar_n hace 2 años
padre
commit
cb6609a850

js/13/index.html → js/13/chat_http/index.html


js/13/index.js → js/13/chat_http/index.js


+ 45 - 0
js/13/chat_socket/app.js

@@ -0,0 +1,45 @@
+const socket = io('http://192.168.1.20:5000/')
+// debugger
+
+btn.addEventListener('click', function () {
+   socket.emit('msg', {nick: user.value, message: text.value})
+})
+
+socket.on('msg', msg => {
+   let messageP = document.createElement('p')
+
+    let message = `${msg.message}`
+
+    const linkRegEx = /https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/
+    const youtubeRegEx = /http(?:s?):\/\/(?:www\.)?youtu(?:be\.com\/watch\?v=|\.be\/)([\w\-\_]*)(&(amp;)?‌​[\w\?‌​=]*)?/
+
+    let matchLink = message.match(linkRegEx)
+    let matchYoutube = message.match(youtubeRegEx)
+    // console.log(matchLink)
+    if (matchLink) {
+        let [link] = matchLink
+        if (link) {
+            let newLink = `<a href="${link}" style="color:blue">${link}</a>`
+            let newMessage = null
+            newMessage = message.replace(link, newLink)
+            if (matchYoutube) {
+                let [, youtubeKey] = matchYoutube
+    
+                if (youtubeKey) {
+                    messageP.innerHTML = `<b>${msg.nick}</b> <br/>  ${newMessage} <br/> <iframe width="560" height="315" 
+                    src="https://www.youtube.com/embed/${youtubeKey}" title="YouTube video player" 
+                    frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; 
+                    picture-in-picture" allowfullscreen></iframe>`
+                } 
+            } else {
+                messageP.innerHTML = `<b>${msg.nick}</b> <br/>  ${newMessage}`
+            }
+        }
+
+    } else {
+        messageP.innerHTML = `<b>${msg.nick}</b> <br/> ${message}`
+    }
+   area.append(messageP)
+})
+
+

+ 27 - 0
js/13/chat_socket/index.html

@@ -0,0 +1,27 @@
+<!DOCTYPE HTML>
+<html>
+    <head>
+        <title>
+            Static File Index.HTML
+        </title>
+        <script src='https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.2.0/socket.io.js'></script>
+    </head>
+    <body>
+        <div id='formContainer'>
+
+         <input id='user'/> <br/>
+
+         <input id='text'/> <br/>
+
+         <button id='btn'>Отправить</button>
+
+         <div id='area'></div>
+
+        </div>
+
+
+
+
+        <script src="./app.js"></script>
+    </body>
+</html>

+ 29 - 0
js/14/gq /app.js

@@ -0,0 +1,29 @@
+
+//fetch(адрес, {method, headers: {}, body: JSON.stringify({query, variables})})
+//method: POST
+//content-type: application/json
+//body: json с query - строка и variables - объект с вложенными параметрами
+
+const gql = (url, query, variables) => fetch(url, {
+      method: 'POST',   
+      headers: {'content-type': 'application/json'}, 
+      body: JSON.stringify({query, variables}),
+   })
+   // .then(response => response.json())
+   // .then(result => console.log(result))
+   ;
+
+(async function() {
+   let response = await gql("http://shop-roles.asmer.fs.a-level.com.ua/graphql", `query cats($q:String) {
+      CategoryFind(query:$q){
+         name goods{
+            name images{
+            url
+            }
+         }
+      }
+   }`, {q: "[{}]"}); //должно приехать { data: {CategoryFind: [........]}}
+   let result = await response.json();
+})()
+
+

+ 13 - 0
js/14/gq /index.html

@@ -0,0 +1,13 @@
+<!DOCTYPE HTML>
+<html lang="ru">
+<head>
+    <meta charset="UTF-8">
+    <meta http-equiv="X-UA-Compatible" content="IE=edge">
+    <meta name="viewport" content="width=device-width, initial-scale=1.0">
+    <title>promise</title>
+</head>
+    <body>
+
+        <script src="./app.js"></script>
+    </body>
+</html>

js/14/index.html → js/14/tasks/index.html


js/14/index.js → js/14/tasks/index.js