Guest User

Untitled

a guest
Dec 23rd, 2018
2,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
CSS 4.37 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6.     <meta http-equiv="X-UA-Compatible" content="ie=edge">
  7.    
  8.     <title>Home</title>
  9.     <link rel="stylesheet" href="styles.css">
  10.     <link href="favicon.png" rel="shortcut icon" type="image/x-icon" />
  11. </head>
  12. <body>
  13.     <div class="container">
  14.         <div id="clock"></div>
  15.         <div class="weather-container">
  16.         <input id="search-field" type="text" name="search-field" onkeypress="return search(event)"/>
  17.         </div>
  18.         <div class="bookmark-container">
  19.             <div class="bookmark-set">
  20.                 <div class="bookmark-title">Daily</div>
  21.                 <div class="bookmark-inner-container">
  22.                     <a class="bookmark" href="https://example.com/" target="_blank">Website1</a>
  23.                     <a class="bookmark" href="https://example.com/" target="_blank">Website2</a>
  24.                     <a class="bookmark" href="https://example.com/" target="_blank">Website3</a>
  25.                     <a class="bookmark" href="https://example.com/" target="_blank">Website4</a>
  26.                 </div>
  27.             </div>
  28.             <div class="bookmark-set">
  29.                 <div class="bookmark-title">Media</div>
  30.                 <div class="bookmark-inner-container">
  31.                     <a class="bookmark" href="https://example.com" target="_blank">Website5</a>
  32.                     <a class="bookmark" href="https://example.com" target="_blank">Website6</a>
  33.                 </div>
  34.             </div>
  35.             <div class="bookmark-set">
  36.                 <div class="bookmark-title">Social</div>
  37.                 <div class="bookmark-inner-container">
  38.                     <a class="bookmark" href="https://example.com" target="_blank">Website7</a>
  39.                 </div>
  40.             </div>
  41.         </div>
  42.     </div>
  43.  
  44.     <script>
  45.         // Search on enter key event
  46.         function search(e) {
  47.             if (e.keyCode == 13) {
  48.                 var val = document.getElementById("search-field").value;
  49.                 window.open("https://google.com/search?q=" + val);
  50.             }
  51.         }
  52.         // Get current time and format
  53.         function getTime() {
  54.             let date = new Date(),
  55.                 min = date.getMinutes(),
  56.                 sec = date.getSeconds(),
  57.                 hour = date.getHours();
  58.  
  59.             return "" +
  60.                 (hour < 10 ? ("0" + hour) : hour) + ":" +
  61.                 (min < 10 ? ("0" + min) : min) + ":" +
  62.                 (sec < 10 ? ("0" + sec) : sec);
  63.         }
  64.  
  65.         window.onload = () => {
  66.             let xhr = new XMLHttpRequest();
  67.             // Request to open weather map
  68.             xhr.open('GET', 'http://api.openweathermap.org/data/2.5/weather?id=4737316&units=imperial&appid=e5b292ae2f9dae5f29e11499c2d82ece');
  69.             xhr.onload = () => {
  70.                 if (xhr.readyState === 4) {
  71.                     if (xhr.status === 200) {
  72.                         let json = JSON.parse(xhr.responseText);
  73.                         console.log(json);
  74.                         document.getElementById("temp").innerHTML = json.main.temp.toFixed(0) + " F";
  75.                         document.getElementById("weather-description").innerHTML = json.weather[0].description;
  76.                     } else {
  77.                         console.log('error msg: ' + xhr.status);
  78.                     }
  79.                 }
  80.             }
  81.             xhr.send();
  82.             // Set up the clock
  83.             document.getElementById("clock").innerHTML = getTime();
  84.             // Set clock interval to tick clock
  85.             setInterval( () => {
  86.                 document.getElementById("clock").innerHTML = getTime();
  87.             },100);
  88.         }
  89.  
  90.         document.addEventListener("keydown", event => {
  91.             if (event.keyCode == 32) {          // Spacebar code to open search
  92.                 document.getElementById('search').style.display = 'flex';
  93.                 document.getElementById('search-field').focus();
  94.             } else if (event.keyCode == 27) {   // Esc to close search
  95.                 document.getElementById('search-field').value = '';
  96.                 document.getElementById('search-field').blur();
  97.                 document.getElementById('search').style.display = 'none';
  98.             }
  99.         });
  100.     </script>
  101. </body>
  102. </html>
Advertisement
Add Comment
Please, Sign In to add comment