Advertisement
patrick121212

btc

Dec 3rd, 2021
580
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.71 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.   <head>
  4.     <meta charset="utf-8" />
  5.     <meta http-equiv="x-ua-compatible" content="ie=edge" />
  6.     <meta name="viewport" content="width=device-width, initial-scale=1" />
  7.  
  8.     <title>Bitcoin Price</title>
  9.   </head>
  10.  
  11.   <style>
  12.     html,
  13.     body {
  14.       height: 100%;
  15.       display: flex;
  16.       flex-direction: column;
  17.       justify-content: center;
  18.       align-items: center;
  19.       text-align: center;
  20.     }
  21.     h1 {
  22.       font-size: 50px;
  23.       margin-block-start: 0;
  24.       margin-block-end: 0;
  25.     }
  26.     p {
  27.       margin-block-start: 0;
  28.       margin-block-end: 0;
  29.     }
  30.     .price {
  31.       font-size: 80px;
  32.       margin: 50px 0;
  33.     }
  34.   </style>
  35.   <body>
  36.     <article>
  37.       <h1>Bitcoin</h1>
  38.       <p class="price"></p>
  39.       <p class="last-update"></p>
  40.     </article>
  41.     <script>
  42.       var DOLLAR = "$";
  43.       var LAST_UPDATE = "Last update: ";
  44.       var price = document.querySelector(".price");
  45.       var lastUpdate = document.querySelector(".last-update");
  46.       function newPrice(res) {
  47.         price.textContent =
  48.           JSON.parse(res.target.response).bitcoin.usd.toLocaleString() + DOLLAR;
  49.         lastUpdate.textContent =
  50.           LAST_UPDATE + new Date().toLocaleString("de-de");
  51.       }
  52.       function requestPrice() {
  53.         var fetchPrice = new XMLHttpRequest();
  54.         fetchPrice.addEventListener("load", newPrice);
  55.         fetchPrice.open(
  56.           "GET",
  57.           "https://api.coingecko.com/api/v3/simple/price?vs_currencies=usd&ids=bitcoin"
  58.        );
  59.         fetchPrice.send();
  60.       }
  61.       requestPrice();
  62.       setInterval(function () {
  63.         requestPrice();
  64.       }, /*30000*/ 120000);
  65.     </script>
  66.   </body>
  67. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement