Aqui está um exemplo de um pequeno site que implementa a técnica Pomodoro. Ele permite ao usuário escolher a temporização, possui um som de aviso padrão e também dá a opção de o usuário carregar um som personalizado.
Estrutura do Projeto
HTML : Estrutura básica do site.
CSS : Estilo simples para tornar o site visualmente agradável.
JavaScript : Lógica para o temporizador e reprodução de som.
Código Completo
1. HTML (index.html)
html Copy code
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Técnica Pomodoro</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="container">
<h1>Técnica Pomodoro</h1>
<div class="controls">
<label for="timer">Tempo (minutos):</label>
<input type="number" id="timer" value="25" min="1">
<button id="startButton">Iniciar</button>
<button id="stopButton" disabled>Parar</button>
</div>
<div class="sound-options">
<p>Som de Aviso:</p>
<audio id="defaultSound" src="default.mp3"></audio>
<input type="file" id="customSoundInput" accept="audio/*">
</div>
<div class="display">
<h2 id="timeDisplay">25:00</h2>
</div>
</div>
<script src="script.js"></script>
</body>
</html>
2. CSS (styles.css)
css Copy code
body {
font-family: Arial, sans-serif;
background-color: #f4f4f9;
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.container {
text-align: center;
background: #fff;
padding: 20px;
border-radius: 10px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
}
h1 {
color: #333;
}
.controls {
margin-bottom: 20px;
}
input[type="number"] {
width: 60px;
padding: 5px;
margin-right: 10px;
}
button {
padding: 10px 20px;
margin: 5px;
border: none;
border-radius: 5px;
cursor: pointer;
}
button#startButton {
background-color: #28a745;
color: white;
}
button#stopButton {
background-color: #dc3545;
color: white;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
.display {
margin-top: 20px;
}
#timeDisplay {
font-size: 48px;
color: #333;
}
.sound-options {
margin-top: 20px;
}
3. JavaScript (script.js)
javascript Copy code
let timerInterval;
let remainingTime = 0;
let audio = document.getElementById('defaultSound');
let customSound = null;
document.getElementById('startButton').addEventListener('click', startTimer);
document.getElementById('stopButton').addEventListener('click', stopTimer);
document.getElementById('customSoundInput').addEventListener('change', handleCustomSound);
function startTimer() {
const minutes = parseInt(document.getElementById('timer').value);
if (isNaN(minutes) || minutes <= 0) {
alert("Por favor, insira um tempo válido.");
return;
}
remainingTime = minutes * 60;
updateDisplay();
document.getElementById('startButton').disabled = true;
document.getElementById('stopButton').disabled = false;
timerInterval = setInterval(() => {
remainingTime--;
updateDisplay();
if (remainingTime <= 0) {
clearInterval(timerInterval);
document.getElementById('startButton').disabled = false;
document.getElementById('stopButton').disabled = true;
playSound();
}
}, 1000);
}
function stopTimer() {
clearInterval(timerInterval);
document.getElementById('startButton').disabled = false;
document.getElementById('stopButton').disabled = true;
remainingTime = 0;
updateDisplay();
}
function updateDisplay() {
const minutes = Math.floor(remainingTime / 60);
const seconds = remainingTime % 60;
document.getElementById('timeDisplay').textContent = `${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
}
function playSound() {
if (customSound) {
customSound.play();
} else {
audio.play();
}
}
function handleCustomSound(event) {
const file = event.target.files[0];
if (file) {
customSound = new Audio(URL.createObjectURL(file));
}
}
Explicação do Funcionamento
Interface do Usuário :
O usuário pode definir o tempo em minutos usando um campo numérico.
Há botões para iniciar e parar o temporizador.
O usuário pode escolher entre o som padrão ou carregar um som personalizado.
Lógica do Temporizador :
O temporizador é atualizado a cada segundo (setInterval).
Quando o tempo chega a zero, o som de aviso é reproduzido.
Som de Aviso :
O som padrão é carregado automaticamente.
Se o usuário carregar um som personalizado, ele será usado no lugar do som padrão.
Estilo :
O design é simples e responsivo, com cores e botões intuitivos.
Observações Finais
Certifique-se de ter um arquivo de áudio chamado default.mp3 na mesma pasta do projeto para o som padrão funcionar.
Este código pode ser expandido com mais funcionalidades, como pausar o temporizador ou adicionar intervalos curtos após cada Pomodoro.
Se precisar de mais ajuda ou quiser melhorias, é só pedir! 😊