* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
font-family: 'Arial', sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
color: #333;
}
.container {
max-width: 600px;
margin: 0 auto;
padding: 20px;
}
header {
text-align: center;
margin-bottom: 40px;
color: white;
}
header h1 {
font-size: 2.5rem;
margin-bottom: 10px;
text-shadow: 2px 2px 4px rgba(0,0,0,0.3);
}
header p {
font-size: 1.1rem;
opacity: 0.9;
}
main {
background: white;
border-radius: 20px;
padding: 40px;
box-shadow: 0 10px 30px rgba(0,0,0,0.2);
}
.timer-display {
text-align: center;
margin-bottom: 30px;
}
.time {
font-size: 4rem;
font-weight: bold;
color: #e74c3c;
margin-bottom: 10px;
font-family: 'Courier New', monospace;
}
.session-type {
font-size: 1.3rem;
color: #666;
font-weight: 500;
}
.controls {
display: flex;
justify-content: center;
gap: 15px;
margin-bottom: 40px;
}
.btn {
padding: 12px 24px;
border: none;
border-radius: 8px;
font-size: 1rem;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
}
.btn-primary {
background: #27ae60;
color: white;
}
.btn-primary:hover {
background: #219a52;
transform: translateY(-2px);
}
.btn-secondary {
background: #f39c12;
color: white;
}
.btn-secondary:hover {
background: #e67e22;
transform: translateY(-2px);
}
.btn-danger {
background: #e74c3c;
color: white;
}
.btn-danger:hover {
background: #c0392b;
transform: translateY(-2px);
}
.btn-small {
padding: 8px 16px;
font-size: 0.9rem;
}
.settings {
border-top: 2px solid #ecf0f1;
padding-top: 30px;
margin-bottom: 30px;
}
.settings h3 {
color: #2c3e50;
margin-bottom: 20px;
font-size: 1.3rem;
}
.setting-group {
display: flex;
align-items: center;
justify-content: space-between;
margin-bottom: 15px;
flex-wrap: wrap;
gap: 10px;
}
.setting-group label {
font-weight: 500;
color: #2c3e50;
flex: 1;
}
.setting-group input[type="number"] {
width: 80px;
padding: 8px;
border: 2px solid #bdc3c7;
border-radius: 5px;
font-size: 1rem;
}
.setting-group input[type="file"] {
flex: 1;
padding: 5px;
}
.pomodoro-info {
text-align: center;
padding: 20px;
background: #ecf0f1;
border-radius: 10px;
}
.cycles {
font-size: 1.2rem;
color: #2c3e50;
}
.timer-active .time {
color: #27ae60;
animation: pulse 1s infinite;
}
.timer-break .time {
color: #3498db;
}
@keyframes pulse {
0% { transform: scale(1); }
50% { transform: scale(1.05); }
100% { transform: scale(1); }
}
@media (max-width: 600px) {
.container {
padding: 10px;
}
main {
padding: 20px;
}
.time {
font-size: 3rem;
}
.controls {
flex-direction: column;
align-items: center;
}
.btn {
width: 200px;
}
.setting-group {
flex-direction: column;
align-items: flex-start;
}
.setting-group input[type="number"] {
width: 100%;
}
}
class PomodoroTimer {
constructor() {
this.timer = null;
this.timeLeft = 0;
this.isActive = false;
this.currentSession = 'focus'; // 'focus', 'shortBreak', 'longBreak'
this.cycleCount = 0;
this.customAudio = null;
this.focusTime = 25;
this.shortBreakTime = 5;
this.longBreakTime = 15;
this.initializeElements();
this.bindEvents();
this.updateDisplay();
}
initializeElements() {
this.timeDisplay = document.getElementById('timeDisplay');
this.sessionTypeDisplay = document.getElementById('sessionType');
this.startBtn = document.getElementById('startBtn');
this.pauseBtn = document.getElementById('pauseBtn');
this.resetBtn = document.getElementById('resetBtn');
this.focusTimeInput = document.getElementById('focusTime');
this.shortBreakInput = document.getElementById('shortBreak');
this.longBreakInput = document.getElementById('longBreak');
this.customSoundInput = document.getElementById('customSound');
this.testSoundBtn = document.getElementById('testSound');
this.cycleCountDisplay = document.getElementById('cycleCount');
this.defaultSound = document.getElementById('defaultSound');
}
bindEvents() {
this.startBtn.addEventListener('click', () => this.start());
this.pauseBtn.addEventListener('click', () => this.pause());
this.resetBtn.addEventListener('click', () => this.reset());
this.testSoundBtn.addEventListener('click', () => this.testSound());
this.focusTimeInput.addEventListener('change', () => this.updateSettings());
this.shortBreakInput.addEventListener('change', () => this.updateSettings());
this.longBreakInput.addEventListener('change', () => this.updateSettings());
this.customSoundInput.addEventListener('change', (e) => this.loadCustomSound(e));
}
updateSettings() {
this.focusTime = parseInt(this.focusTimeInput.value);
this.shortBreakTime = parseInt(this.shortBreakInput.value);
this.longBreakTime = parseInt(this.longBreakInput.value);
if (!this.isActive) {
this.reset();
}
}
loadCustomSound(event) {
const file = event.target.files[0];
if (file) {
const url = URL.createObjectURL(file);
this.customAudio = new Audio(url);
}
}
testSound() {
this.playSound();
}
playSound() {
try {
if (this.customAudio) {
this.customAudio.currentTime = 0;
this.customAudio.play();
} else {
this.defaultSound.currentTime = 0;
this.defaultSound.play();
}
} catch (error) {
console.log('Erro ao reproduzir som:', error);
}
}
start() {
if (!this.isActive) {
this.isActive = true;
this.startBtn.textContent = 'Em Andamento';
this.startBtn.disabled = true;
document.body.classList.add('timer-active');
this.timer = setInterval(() => {
this.timeLeft--;
this.updateDisplay();
if (this.timeLeft <= 0) {
this.completeSession();
}
}, 1000);
}
}
pause() {
if (this.isActive) {
this.isActive = false;
clearInterval(this.timer);
this.startBtn.textContent = 'Continuar';
this.startBtn.disabled = false;
document.body.classList.remove('timer-active');
}
}
reset() {
this.isActive = false;
clearInterval(this.timer);
this.currentSession = 'focus';
this.timeLeft = this.focusTime * 60;
this.startBtn.textContent = 'Iniciar';
this.startBtn.disabled = false;
document.body.classList.remove('timer-active', 'timer-break');
this.updateDisplay();
}
completeSession() {
this.playSound();
this.isActive = false;
clearInterval(this.timer);
if (this.currentSession === 'focus') {
this.cycleCount++;
this.cycleCountDisplay.textContent = this.cycleCount;
// Determinar próxima sessão
if (this.cycleCount % 4 === 0) {
this.currentSession = 'longBreak';
this.timeLeft = this.longBreakTime * 60;
} else {
this.currentSession = 'shortBreak';
this.timeLeft = this.shortBreakTime * 60;
}
document.body.classList.add('timer-break');
} else {
this.currentSession = 'focus';
this.timeLeft = this.focusTime * 60;
document.body.classList.remove('timer-break');
}
this.startBtn.textContent = 'Iniciar';
this.startBtn.disabled = false;
document.body.classList.remove('timer-active');
this.updateDisplay();
// Mostrar notificação
this.showNotification();
}
showNotification() {
const messages = {
focus: '🍅 Hora de focar! Vamos trabalhar!',
shortBreak: '☕ Pausa curta! Relaxe um pouco.',
longBreak: '🌟 Pausa longa! Você merece descansar!'
};
if ('Notification' in window && Notification.permission === 'granted') {
new Notification('Pomodoro Timer', {
body: messages[this.currentSession],
icon: '🍅'
});
} else if ('Notification' in window) {
Notification.requestPermission();
}
alert(messages[this.currentSession]);
}
updateDisplay() {
const minutes = Math.floor(this.timeLeft / 60);
const seconds = this.timeLeft % 60;
this.timeDisplay.textContent =
`${minutes.toString().padStart(2, '0')}:${seconds.toString().padStart(2, '0')}`;
const sessionNames = {
focus: 'Tempo de Foco',
shortBreak: 'Pausa Curta',
longBreak: 'Pausa Longa'
};
this.sessionTypeDisplay.textContent = sessionNames[this.currentSession];
// Atualizar título da página
document.title = `${this.timeDisplay.textContent} - ${sessionNames[this.currentSession]}`;
}
getCurrentTime() {
const timeMap = {
focus: this.focusTime,
shortBreak: this.shortBreakTime,
longBreak: this.longBreakTime
};
return timeMap[this.currentSession] * 60;
}
}
// Inicializar o timer quando a página carregar
document.addEventListener('DOMContentLoaded', () => {
const pomodoro = new PomodoroTimer();
pomodoro.timeLeft = pomodoro.getCurrentTime();
pomodoro.updateDisplay();
// Solicitar permissão para notificações
if ('Notification' in window) {
Notification.requestPermission();
}
});