Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <span class="timer" id="s2" style='font-size:16px; color: #A6ABB9;'></span>
- <script>
- function countdown( elementName, minutes, seconds )
- {
- var element, endTime, hours, mins, msLeft, time;
- function twoDigits( n )
- {
- return (n <= 9 ? "0" + n : n);
- }
- function updateTimer()
- {
- msLeft = endTime - (+new Date);
- if ( msLeft < 1000 ) {
- // soundData should contain any valid file converted to base64
- // look up "file to base64" to get one
- // 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
- const soundData = "";
- const snd = new Audio(`data:audio/mp3;base64,${soundData}`);
- sound.play();
- element.innerHTML = "<span style='color:#CC5B5B'>TIME</span>";
- } else {
- time = new Date( msLeft );
- hours = time.getUTCHours();
- mins = time.getUTCMinutes();
- element.innerHTML = (hours ? hours + ':' + twoDigits( mins ) : mins) + ':' + twoDigits( time.getUTCSeconds() );
- setTimeout( updateTimer, time.getUTCMilliseconds() + 500 );
- }
- }
- element = document.getElementById( elementName );
- endTime = (+new Date) + 1000 * (60*minutes + seconds) + 500;
- updateTimer();
- }
- countdown("s2", 0, 10 ); //2nd value is the minute, 3rd is the seconds
- </script>
Add Comment
Please, Sign In to add comment