timer.html 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <html>
  2. <head>
  3. <title>Timer</title>
  4. <link rel="stylesheet" href="../script/semantic/semantic.min.css">
  5. <script src="../script/jquery.min.js"></script>
  6. <script src="../script/ao_module.js"></script>
  7. <style>
  8. body{
  9. padding-top:40px;
  10. padding-bottom:50px;
  11. background-color:rgba(242, 242, 242, 0.85);
  12. backdrop-filter: blur(4px) !important;
  13. overflow: hidden;
  14. }
  15. </style>
  16. </head>
  17. <body>
  18. <div class="ui container" style="position:absolute;left:0;right:0;width:100%;" align="center">
  19. <div class="ui grid" style="margin-top: -30px;">
  20. <div class="five wide column">
  21. <div class="ui statistic">
  22. <div id="hour" class="value">00</div>
  23. <div class="label">Hours</div>
  24. </div><br>
  25. <div class="ui icon tiny buttons">
  26. <button class="ui button" onClick="adjustValue('hour',-1);"><i class="minus icon"></i></button>
  27. <button class="ui button" onClick="resetTimer('hour');"><i class="undo icon"></i></button>
  28. <button class="ui button"onClick="adjustValue('hour',1);"><i class="plus icon"></i></button>
  29. </div>
  30. </div>
  31. <div class="five wide column">
  32. <div class="ui statistic">
  33. <div id="min" class="value">00</div>
  34. <div class="label">Minutes</div>
  35. </div><br>
  36. <div class="ui icon tiny buttons">
  37. <button class="ui button" onClick="adjustValue('min',-1);"><i class="minus icon"></i></button>
  38. <button class="ui button" onClick="resetTimer('min');"><i class="undo icon"></i></button>
  39. <button class="ui button"onClick="adjustValue('min',1);"><i class="plus icon"></i></button>
  40. </div>
  41. </div>
  42. <div class="five wide column">
  43. <div class="ui statistic">
  44. <div id="sec" class="value">00</div>
  45. <div class="label">Seconds</div>
  46. </div><br>
  47. <div class="ui icon tiny buttons">
  48. <button class="ui button" onClick="adjustValue('sec',-1);"><i class="minus icon"></i></button>
  49. <button class="ui button" onClick="resetTimer('sec');"><i class="undo icon"></i></button>
  50. <button class="ui button"onClick="adjustValue('sec',1);"><i class="plus icon"></i></button>
  51. </div>
  52. </div>
  53. <div class="one wide column">
  54. <button id="startbtn" class="ui positive tiny icon button" onClick="startCountDown();" style="position:fixed;top:3px;right:3px;">
  55. <i class="play icon"></i>
  56. </button>
  57. <button id="pausebtn" class="ui basic tiny icon button disabled" onClick="pauseCountDown();" style="position:fixed;top:40px;right:3px;">
  58. <i class="pause icon"></i>
  59. </button>
  60. <button id="stopalarm" class="ui negative tiny icon button disabled" onClick="stopAlarm();" style="position:fixed;top:80px;right:3px;">
  61. <i class="alarm mute icon"></i>
  62. </button>
  63. </div>
  64. </div>
  65. </div>
  66. <script>
  67. //Init the timer window
  68. ao_module_setFixedWindowSize();
  69. ao_module_setWindowSize(380,190);
  70. ao_module_setWindowTitle("Countdown Timer - Ready");
  71. if (ao_module_windowID == false){
  72. $("body").append("<div style='position:fixed;bottom:10px;left:10px;'>[Warning] Seems you are not opening this module under virtual desktop mode. Some functions might be limited or not fully supported.</div>");
  73. }
  74. //Global variable
  75. var countingDown = false;
  76. var counter;
  77. setInterval(timerTick,1000);
  78. var alarmStartTime = 0;
  79. var volIncreaseInterval;
  80. var audio;
  81. //Handle button pressed
  82. function adjustValue(target,offset){
  83. if ($("#" + target).length == 0){
  84. return;
  85. }
  86. var currentSec = parseInt($("#" + target).text());
  87. if (target == "sec" || target == "min"){
  88. if (currentSec == 0 && offset < 0){
  89. currentSec = 60;
  90. }else if (currentSec == 59 && offset > 0){
  91. currentSec = -1;
  92. }
  93. currentSec += offset;
  94. updateCounterValue(target,currentSec);
  95. }else{
  96. //This logic loop controls the hour counter
  97. if (currentSec == 0 && offset < 0){
  98. currentSec = 24;
  99. }else if (currentSec == 23 && offset > 0){
  100. currentSec = -1;
  101. }
  102. currentSec += offset;
  103. updateCounterValue(target,currentSec);
  104. }
  105. }
  106. function resetTimer(target){
  107. $("#" + target).text("00");
  108. }
  109. function updateCounterValue(target,num){
  110. $("#" + target).text(fillZero(num));
  111. }
  112. function fillZero(value){
  113. if (value < 10){
  114. return "0" + value;
  115. }else{
  116. return value + "";
  117. }
  118. }
  119. function startCountDown(){
  120. countingDown = true;
  121. ao_module_setWindowTitle("Countdown Timer - Counting");
  122. }
  123. function pauseCountDown(){
  124. countingDown = false;
  125. ao_module_setWindowTitle("Countdown Timer - Ready");
  126. }
  127. function resetAllTimer(){
  128. updateCounterValue("sec",0);
  129. updateCounterValue("min",0);
  130. updateCounterValue("hour",0);
  131. }
  132. //Looping functions for timer ticks
  133. function timerTick(){
  134. //This function should be running every 1 second
  135. if (countingDown == true){
  136. $("#startbtn").addClass("disabled");
  137. $("#pausebtn").removeClass("disabled");
  138. var sec = parseInt($("#sec").text());
  139. var min = parseInt($("#min").text());
  140. var hour = parseInt($("#hour").text());
  141. //console.log("Coutning down");
  142. if (sec > 0){
  143. sec = sec - 1;
  144. }else if (sec == 0){
  145. sec = 59;
  146. if (min > 0){
  147. min = min -1;
  148. }else if (min == 0){
  149. min = 59;
  150. if (hour > 0){
  151. hour = hour -1;
  152. }else if (hour == 0){
  153. countingDown = false;
  154. //parent.msgbox("Timeout!","Timer Notification");
  155. startTimeoutEvents();
  156. resetAllTimer();
  157. return;
  158. }
  159. }
  160. }
  161. updateCounterValue("sec",sec);
  162. updateCounterValue("min",min);
  163. updateCounterValue("hour",hour);
  164. }else{
  165. $("#startbtn").removeClass("disabled");
  166. $("#pausebtn").addClass("disabled");
  167. }
  168. }
  169. function startTimeoutEvents(){
  170. if (alarmStartTime != 0){
  171. stopAlarm();
  172. }
  173. audio = new Audio('sound/imuslab_theme.mp3');
  174. audio.volume = 0.02;
  175. audio.play();
  176. alarmStartTime = time();
  177. volIncreaseInterval = setInterval( increaseVolumeALittleBit, 5000);
  178. $("#stopalarm").removeClass("disabled");
  179. ao_module_setWindowTitle("Countdown Timer - Time Out!");
  180. }
  181. function stopAlarm(){
  182. $("#stopalarm").addClass("disabled");
  183. clearInterval(volIncreaseInterval);
  184. audio.pause();
  185. audio.currentTime = 0;
  186. ao_module_setWindowTitle("Countdown Timer - Ready");
  187. alarmStartTime = 0;
  188. }
  189. function increaseVolumeALittleBit(){
  190. audio.volume += 0.02;
  191. console.log("[Timer] Alarm volume increased to: " + audio.volume);
  192. }
  193. function time(){
  194. return Math.floor(Date.now() / 1000);
  195. }
  196. </script>
  197. </body>
  198. </html>