Advertisement
peyj_

Simple time tracker

Jul 21st, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.01 KB | None | 0 0
  1. <script>
  2.     var addShit = function() {
  3.         var list = document.getElementById("list");
  4.         var input = document.getElementById("inputText");
  5.  
  6.         var li = document.createElement("li");
  7.         li.appendChild(getTimestamp(input.value.toString()));
  8.         input.value = "";
  9.         list.appendChild(li);
  10.     };
  11.  
  12.     var getTimestamp = function (text) {
  13.         var d = new Date();
  14.         var fd = {
  15.             h: d.getHours().toString(),
  16.             m: d.getMinutes().toString(),
  17.             s: d.getSeconds().toString(),
  18.         }
  19.  
  20.         for (var prop in fd) {
  21.             if (fd[prop].length === 1) {
  22.                 fd[prop] = "0" + fd[prop];
  23.             }
  24.         }
  25.  
  26.         var prf = fd.h + ":" + fd.m + " - ";
  27.  
  28.         var p = document.createElement("p");
  29.         p.innerHTML = prf + text;
  30.  
  31.         return p;
  32.     };
  33. </script>
  34.  
  35. <ul id=list>
  36. </ul>
  37. <button onclick="addShit()"> add </button>
  38. <input id=inputText onkeydown="if (event.keyCode == 13) {addShit();}" ></input>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement