Browse Source

change 12

Olga1108 4 years ago
parent
commit
c59feb6d67
4 changed files with 75 additions and 0 deletions
  1. 17 0
      js12.1/index.html
  2. 13 0
      js12.1/index.js
  3. 17 0
      js12.2/index.html
  4. 28 0
      js12.2/index.js

+ 17 - 0
js12.1/index.html

@@ -0,0 +1,17 @@
+!DOCTYPE html>
+<html lang='en'>
+    <head>
+        <meta charset='UTF-8' />
+        <meta name='viewport' content='width=device-width, initial-scale=1.0' />
+        <title>Home Work 12 JS</title>
+        <style type="text/css">
+            body {
+                color: red;
+            }
+        </style>
+    </head>
+    <body>
+        <h1>Home Work 12</h1>
+        <script src='index.js'></script>    
+    </body>
+</html>

+ 13 - 0
js12.1/index.js

@@ -0,0 +1,13 @@
+// Захостить на гитхабе приложение, которое:
+
+// читает куки на клиенте, и если там есть дата последнего посещения, выводит ее на страницу
+// пишет в куки на клиенте текущую дату посещения
+
+let p = document.body.appendChild(document.createElement('p'));
+var res = document.cookie
+    .split ( "; " )
+    .map ( x =>  {
+        var tmp = x.split ( "=" );
+        tmp[0] === 'Your last visit' ? p.innerText = tmp[0] + ' : '+ tmp[1].split( 'GMT' )[0]: p.innerText ='Hello! Your first visit!';
+})
+ document.cookie =`Your last visit = ${new Date}`

+ 17 - 0
js12.2/index.html

@@ -0,0 +1,17 @@
+!DOCTYPE html>
+<html lang='en'>
+    <head>
+        <meta charset='UTF-8' />
+        <meta name='viewport' content='width=device-width, initial-scale=1.0' />
+        <title>Home Work 12 JS</title>
+        <style type="text/css">
+            body {
+                color: red;
+            }
+        </style>
+    </head>
+    <body>
+        <h1>Home Work 12</h1>
+        <script src='index.js'></script>    
+    </body>
+</html>

+ 28 - 0
js12.2/index.js

@@ -0,0 +1,28 @@
+//  localStorage
+// Объявить функцию, которая будет вызываться в момент изменения хэш-части адреса страницы
+
+// и сохранять в localStorage клиента hash-часть адреса страницы как pageId
+// и время входа ( в секундах ) как startTime
+
+// Назначить эту функцию обработчиком события hashchange объекта window
+
+// Желательно, чтобы при изменении хеш-части адреса происходило обновление контента страницы без перезагрузки
+// ( например, изменялся заголовок и картинка, чтобы создать иллюзию перехода на новую страницу )
+
+// Отслеживать в панели разработчика изменения в localStorage
+
+
+let text =document.body.appendChild(document.createElement('p'));
+document.body.style.backgroundImage=`url(https://picsum.photos/900/900/?random)`;
+document.body.style.backgroundSize= 'cover';
+document.body.style.fontSize = '40px';
+const historyArr = [];
+change = function() {
+    historyArr.push( { 'pageId': location.hash, 'startTime': Math.round(new Date().getTime()/1000)});
+    localStorage.setItem ( 'history', JSON.stringify(historyArr));
+    document.body.style.backgroundImage=`url(https://picsum.photos/900/900/?random/${Math.round((Math.random())*1000)})`;
+    
+    text.innerHTML = 'This is page number :' + location.hash.substring(1);
+};
+
+window.addEventListener('hashchange', change);