Guest User

Untitled

a guest
Apr 11th, 2023
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. <span class="timer" id="s2" style='font-size:16px; color: #A6ABB9;'></span>
  2. <script>
  3. function countdown( elementName, minutes, seconds )
  4. {
  5. var element, endTime, hours, mins, msLeft, time;
  6. function twoDigits( n )
  7. {
  8. return (n <= 9 ? "0" + n : n);
  9. }
  10. function updateTimer()
  11. {
  12. msLeft = endTime - (+new Date);
  13. if ( msLeft < 1000 ) {
  14. // soundData should contain any valid file converted to base64
  15. // look up "file to base64" to get one
  16. // if you want the particular addon alert, check here https://github.com/glutanimate/speed-focus-mode/blob/main/src/speed_focus_mode/sounds/alert.mp3
  17. const soundData = "pastehere";
  18. const sound = new Audio(`data:audio/mp3;base64,${soundData}`);
  19. sound.play();
  20. element.innerHTML = "<span style='color:#CC5B5B'>TIME</span>";
  21. } else {
  22. time = new Date( msLeft );
  23. hours = time.getUTCHours();
  24. mins = time.getUTCMinutes();
  25. element.innerHTML = (hours ? hours + ':' + twoDigits( mins ) : mins) + ':' + twoDigits( time.getUTCSeconds() );
  26. setTimeout( updateTimer, time.getUTCMilliseconds() + 500 );
  27. }
  28. }
  29. element = document.getElementById( elementName );
  30. endTime = (+new Date) + 1000 * (60*minutes + seconds) + 500;
  31. updateTimer();
  32. }
  33. countdown("s2", 0, 10 ); //2nd value is the minute, 3rd is the seconds
  34. </script>
Add Comment
Please, Sign In to add comment