diff --git a/www/script.js b/www/script.js index 944a1fc..bf18cab 100644 --- a/www/script.js +++ b/www/script.js @@ -6,6 +6,8 @@ const body = document.querySelector("body"); const hintCheckbox = document.querySelector("#hintCheck"); const timerInput = document.getElementById("timerInput"); +const isCordova = typeof cordova !== 'undefined'; + const theme = localStorage.getItem('theme'); if (theme == "light") { @@ -86,10 +88,11 @@ startButton.addEventListener('click', () => { break; } case 3: { - if (!!navigator.vibrate) { + if (isCordova && !!navigator.vibrate) { navigator.vibrate(0); } - if (!!StayAwake.enableScreenTimeout) { + + if (isCordova && !!StayAwake.enableScreenTimeout) { StayAwake.enableScreenTimeout(); } clearInterval(timer); @@ -159,26 +162,28 @@ startButton.addEventListener('click', () => { var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); timerElement.innerText = `${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`; - if (!!StayAwake.disableScreenTimeout) { + + if (isCordova && !!StayAwake.disableScreenTimeout) { StayAwake.disableScreenTimeout(); } if (distance < 0) { clearInterval(timer); - + if (!!navigator.vibrate) { navigator.vibrate([1000, 500, 1000, 2000, 1000, 500, 1000, 2000, 1000, 500, 1000, 2000]); } - - if (!!StayAwake.enableScreenTimeout) { + + if (isCordova && !!StayAwake.enableScreenTimeout) { StayAwake.enableScreenTimeout(); } - + timerElement.innerText = "Acabou!"; } }, 1000) } + function changeTheme(){ body.classList.toggle('light-theme'); console.log(body.classList.contains('light-theme') ? "light" : "dark")