timer.html 9.1 KB

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