Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="UTF-8">
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
- <meta http-equiv="X-UA-Compatible" content="ie=edge">
- <title>Home</title>
- <link rel="stylesheet" href="styles.css">
- <link href="favicon.png" rel="shortcut icon" type="image/x-icon" />
- </head>
- <body>
- <div class="container">
- <div id="clock"></div>
- <div class="weather-container">
- <input id="search-field" type="text" name="search-field" onkeypress="return search(event)"/>
- </div>
- <div class="bookmark-container">
- <div class="bookmark-set">
- <div class="bookmark-title">Daily</div>
- <div class="bookmark-inner-container">
- <a class="bookmark" href="https://example.com/" target="_blank">Website1</a>
- <a class="bookmark" href="https://example.com/" target="_blank">Website2</a>
- <a class="bookmark" href="https://example.com/" target="_blank">Website3</a>
- <a class="bookmark" href="https://example.com/" target="_blank">Website4</a>
- </div>
- </div>
- <div class="bookmark-set">
- <div class="bookmark-title">Media</div>
- <div class="bookmark-inner-container">
- <a class="bookmark" href="https://example.com" target="_blank">Website5</a>
- <a class="bookmark" href="https://example.com" target="_blank">Website6</a>
- </div>
- </div>
- <div class="bookmark-set">
- <div class="bookmark-title">Social</div>
- <div class="bookmark-inner-container">
- <a class="bookmark" href="https://example.com" target="_blank">Website7</a>
- </div>
- </div>
- </div>
- </div>
- <script>
- // Search on enter key event
- function search(e) {
- if (e.keyCode == 13) {
- var val = document.getElementById("search-field").value;
- window.open("https://google.com/search?q=" + val);
- }
- }
- // Get current time and format
- function getTime() {
- let date = new Date(),
- min = date.getMinutes(),
- sec = date.getSeconds(),
- hour = date.getHours();
- return "" +
- (hour < 10 ? ("0" + hour) : hour) + ":" +
- (min < 10 ? ("0" + min) : min) + ":" +
- (sec < 10 ? ("0" + sec) : sec);
- }
- window.onload = () => {
- let xhr = new XMLHttpRequest();
- // Request to open weather map
- xhr.open('GET', 'http://api.openweathermap.org/data/2.5/weather?id=4737316&units=imperial&appid=e5b292ae2f9dae5f29e11499c2d82ece');
- xhr.onload = () => {
- if (xhr.readyState === 4) {
- if (xhr.status === 200) {
- let json = JSON.parse(xhr.responseText);
- console.log(json);
- document.getElementById("temp").innerHTML = json.main.temp.toFixed(0) + " F";
- document.getElementById("weather-description").innerHTML = json.weather[0].description;
- } else {
- console.log('error msg: ' + xhr.status);
- }
- }
- }
- xhr.send();
- // Set up the clock
- document.getElementById("clock").innerHTML = getTime();
- // Set clock interval to tick clock
- setInterval( () => {
- document.getElementById("clock").innerHTML = getTime();
- },100);
- }
- document.addEventListener("keydown", event => {
- if (event.keyCode == 32) { // Spacebar code to open search
- document.getElementById('search').style.display = 'flex';
- document.getElementById('search-field').focus();
- } else if (event.keyCode == 27) { // Esc to close search
- document.getElementById('search-field').value = '';
- document.getElementById('search-field').blur();
- document.getElementById('search').style.display = 'none';
- }
- });
- </script>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment