LimePaste888

Basic timer.

Apr 8th, 2022 (edited)
708
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 3.47 KB | None | 0 0
  1. <html><head>
  2. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  3. <title>Timer</title>
  4. </head>
  5.  
  6. <body style="font-family:Consolas, Lucida Console, Verdana; background: #033; color: cyan">
  7.  
  8. <p id="1" style="margin:0px 0px 12px 0px">Press Start! to start</p>
  9. <div style="background: cyan; margin: 0px 0px 8px 0px; padding:4px"><div id="2" style="height: 72px;"></div></div>
  10. <button onclick="e = true;f = performance.now() / 1000" style="background: green; color: white; border: none; padding: 8px; margin: 0px 0px 8px 0px; font-family: Consolas, Lucida Console, Verdana">Start! (Restart)</button>
  11. <p style="margin:0px 0px 4px 0px">Timer length:</p>
  12. <textarea id="3" style="resize: none" rows="1">?</textarea>
  13. <br>
  14. <select id="4" style="font-family:Consolas, Lucida Console, Verdana">
  15.     <option value="1">seconds</option>
  16.     <option value="60">minutes</option>
  17.     <option value="3600">hours (3600 seconds.)</option>
  18.     <option value="86400">days (That's a little overboard don't you think?)</option>
  19.     <option value="604800">weeks (Wha- why?!)</option>
  20.     <option value="2592000">months (stop.)</option>
  21.     <option value="31557600">years (Huh. Time capsules.)</option>
  22. </select>
  23. <p id="5">Waiting for response...</p>
  24. <p id="6"></p>
  25. <button onclick="a0 -= 1;">Previous station</button><button onclick="a0 += 1;">Next station</button>
  26. <br>
  27. <button onclick="if (rail == 1) {rail = 2} else {rail = 1}">Switch rail</button>
  28. <script>
  29.  
  30. function floor3digits(number) {return Math.floor(number * 1000) / 1000}
  31. a = document.getElementById("3").value
  32. b = a0 = 0
  33. rail = 1
  34. stations = ['Center','Lake','Snowdin Town','Hotland','Station','Blossom Street','Flower Pier','Space','Sleepwalk Station']
  35. rail1 = [0, 1, 2, 3, 4, 5, 6]
  36. rail2 = [0, 7, 8]
  37. function x() {
  38.     a = parseFloat(document.getElementById("3").value) * parseFloat(document.getElementById("4").value)
  39.     // Used to represent the text-area's value.
  40.     b = performance.now() / 1000 - f
  41.     // The seconds since you've pressed the Start! button.
  42.     c = floor3digits((b * -1) + a)
  43.     // The overall countdown in seconds.
  44.     document.getElementById("1").innerText = c + " seconds\n" + floor3digits(c / 60) + " minutes\n" + floor3digits(c / 3600) + " hours\n" + floor3digits(((b / (a * -0.01)) + 100)) + "% until end"
  45.     document.getElementById("2").style.width = c > 0 ? ((((b / (a * -0.01))) + 100) + "%").toString() : ((((b / (a * 0.01))) - 100) + "%").toString()
  46.     document.getElementById("2").style.background = c > 0 ? "#222 url(\"lefttile.png\")" : "#333c"
  47.     document.getElementById("2").style.backgroundSize = "72px"
  48.     qwe = document.getElementById("5")
  49.     asd = document.getElementById("6")
  50.     qwe.innerHTML = stations[rail == 1 ? rail1[a0] : rail2[a0]]
  51.     asd.innerHTML = a0.toString() + " station\n" + rail.toString() + " rail"
  52.     if (! qwe.innerHTML in stations) {while (! qwe.innerHTML in stations) {qwe.innerHTML = parseInt(qwe.innerHTML) + 1}}
  53.     if (a0 < 0) {a0 = [6,2][rail - 1]}
  54.     if (a0 > [6,2][rail - 1]) {a0 = 0}
  55. }
  56. var c
  57. // Defined as undefined for preventing error.
  58. d = new Audio("8bit-0.mp3")
  59. // Played in y(): Alarm sound.
  60. function y() {
  61.     if (c < 0) {
  62.         d.play()
  63.     }}
  64. setInterval(y, 1000)
  65. e = false
  66. // If you have pressed the Start! button yet.
  67. f = undefined
  68. // The distance between the last Start! press and the start of the document.
  69. function z() {
  70.     if (e == true) {setInterval(x, 20)}
  71.     else {setTimeout(z, 20)}
  72. }
  73. z()
  74.  
  75. </script>
  76. <style>button{font-family:Consolas, Lucida Console, Verdana;width:100px}</style>
  77.  
  78. </body></html>
Add Comment
Please, Sign In to add comment