Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

buia #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
File renamed without changes.
3 changes: 2 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
href="https://fonts.googleapis.com/css2?family=Montserrat:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Prata&family=Unbounded:wght@200;300;400;500;600;700;800;900&display=swap"
rel="stylesheet">
<link rel="stylesheet" href="./styles.css">
<script src="./script.js" defer></script>
</head>

<body>
Expand Down Expand Up @@ -71,7 +72,7 @@ <h1 class="app__title">

<footer class="app__footer">
<p class="app__footer-text">
Projeto fictício e sem fins comerciais. Imagens geradas por IA no Adobe Firefly.Desenvolvido por Alura.
Projeto fictício e sem fins comerciais. Imagens geradas por IA no Adobe Firefly.Desenvolvido por Vitor.
</p>
</footer>
</main>
Expand Down
116 changes: 116 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
const html = document.querySelector('html')
const focoBt = document.querySelector('.app__card-button--foco')
const curtoBt = document.querySelector('.app__card-button--curto')
const longoBt = document.querySelector('.app__card-button--longo')
const banner = document.querySelector('.app__image')
const titulo = document.querySelector('.app__title')
const botoes = document.querySelectorAll('.app__card-button')
const startPauseBt = document.querySelector('#start-pause')
const musicaFocoInput = document.querySelector('#alternar-musica')
const iniciarOuPausarBt = document.querySelector('#start-pause span')
const iniciarOuPausarBtIcone = document.querySelector(".app__card-primary-butto-icon")
const tempoNaTela = document.querySelector('#timer')

const musica = new Audio('/sons/luna-rise-part-one.mp3')
const audioPlay = new Audio('/sons/play.wav');
const audioPausa = new Audio('/sons/pause.mp3');
const audioTempoFinalizado = new Audio('./sons/beep.mp3')

let tempoDecorridoEmSegundos = 1500
let intervaloId = null

musica.loop = true

musicaFocoInput.addEventListener('change', () => {
if(musica.paused) {
musica.play()
} else {
musica.pause()
}
})

focoBt.addEventListener('click', () => {
tempoDecorridoEmSegundos = 1500
alterarContexto('foco')
focoBt.classList.add('active')
})

curtoBt.addEventListener('click', () => {
tempoDecorridoEmSegundos = 300
alterarContexto('descanso-curto')
curtoBt.classList.add('active')
})

longoBt.addEventListener('click', () => {
tempoDecorridoEmSegundos = 900
alterarContexto('descanso-longo')
longoBt.classList.add('active')
})

function alterarContexto(contexto) {
mostrarTempo()
botoes.forEach(function (contexto){
contexto.classList.remove('active')
})
html.setAttribute('data-contexto', contexto)
banner.setAttribute('src', `/imagens/${contexto}.png`)
switch (contexto) {
case "foco":
titulo.innerHTML = `
Otimize sua produtividade,<br>
<strong class="app__title-strong">mergulhe no que importa.</strong>
`
break;
case "descanso-curto":
titulo.innerHTML = `
Que tal dar uma respirada? <strong class="app__title-strong">Faça uma pausa curta!</strong>
`
break;
case "descanso-longo":
titulo.innerHTML = `
Hora de voltar à superfície.<strong class="app__title-strong"> Faça uma pausa longa.</strong>
`
default:
break;
}
}

const contagemRegressiva = () => {
if(tempoDecorridoEmSegundos <= 0){
audioTempoFinalizado.play()
alert('Tempo finalizado!')
zerar()
return
}
tempoDecorridoEmSegundos -= 1
mostrarTempo()
}

startPauseBt.addEventListener('click', iniciarOuPausar)

function iniciarOuPausar() {
if(intervaloId){
audioPausa.play()
zerar()
return
}
audioPlay.play()
intervaloId = setInterval(contagemRegressiva, 1000)
iniciarOuPausarBt.textContent = "Pausar"
iniciarOuPausarBtIcone.setAttribute('src', `/imagens/pause.png`)
}

function zerar() {
clearInterval(intervaloId)
iniciarOuPausarBt.textContent = "Começar"
iniciarOuPausarBtIcone.setAttribute('src', `/imagens/play_arrow.png`)
intervaloId = null
}

function mostrarTempo() {
const tempo = new Date(tempoDecorridoEmSegundos * 1000)
const tempoFormatado = tempo.toLocaleTimeString('pt-Br', {minute: '2-digit', second: '2-digit'})
tempoNaTela.innerHTML = `${tempoFormatado}`
}

mostrarTempo()
6 changes: 2 additions & 4 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -227,16 +227,14 @@ h1, h2, h3, h4, h5, h6 {
visibility: hidden;
}

/* fim - toggle */

/* Para Tablets */
@media (max-width: 1024px) and (min-width: 768px) {
.app__section-banner-container {
width: 48rem;
}
}

/* Para Celulares */

@media (max-width: 767px) {
.app__section-banner-container {
width: 32rem;
Expand All @@ -249,4 +247,4 @@ h1, h2, h3, h4, h5, h6 {
.app__card-timer {
font-size: 6rem;
}
}
}