Study Timer
Use the Pomodoro technique to study efficiently. Set focused study sessions with short and long breaks to maximise productivity.
Advertisement
Advertisement
What is the Pomodoro technique?
The Pomodoro technique breaks work into 25-minute focused sessions separated by short breaks. After 4 sessions you take a longer break. This method improves focus, reduces mental fatigue, and helps you track how you spend your time.
let mode='study', running=false, timer=null, remaining=0, total=0, sessions=0, focusMin=0;
const modeColors={study:'#FFD166',short:'#1D9E75',long:'#378ADD'};
const modeLabels={study:'Focus time',short:'Short break',long:'Long break'};
function getMins(){return{study:+document.getElementById('study-min').value||25,short:+document.getElementById('short-min').value||5,long:+document.getElementById('long-min').value||15};}
function setMode(m,btn){
if(running)return;
mode=m;
document.querySelectorAll('.mode-btn').forEach(b=>b.classList.remove('active'));
btn.classList.add('active');
resetTimer();
}
function resetTimer(){
clearInterval(timer);running=false;
const mins=getMins();
remaining=total=mins[mode]*60;
updateDisplay();
document.getElementById('start-btn').textContent='Start';
document.getElementById('progress-ring').style.borderTopColor=modeColors[mode];
document.getElementById('progress-ring').style.transform='rotate(-90deg)';
document.getElementById('timer-label').textContent=modeLabels[mode];
}
function toggleTimer(){
if(running){clearInterval(timer);running=false;document.getElementById('start-btn').textContent='Resume';}
else{running=true;document.getElementById('start-btn').textContent='Pause';
timer=setInterval(()=>{
remaining--;
if(remaining<=0){clearInterval(timer);running=false;onComplete();}
updateDisplay();
},1000);
}
}
function onComplete(){
if(mode==='study'){sessions++;focusMin+=getMins().study;document.getElementById('stat-sessions').textContent=sessions;document.getElementById('stat-focus').textContent=focusMin+' min';document.getElementById('stat-streak').textContent=sessions;}
alert(mode==='study'?'Great work! Take a break.':'Break over! Time to focus.');
resetTimer();
renderDots();
}
function updateDisplay(){
const m=Math.floor(remaining/60).toString().padStart(2,'0');
const s=(remaining%60).toString().padStart(2,'0');
document.getElementById('timer-display').textContent=m+':'+s;
const pct=remaining/total;
const deg=360*(1-pct)-90;
document.getElementById('progress-ring').style.transform=`rotate(${deg}deg)`;
}
function renderDots(){
const dots=document.getElementById('session-dots');
dots.innerHTML=[0,1,2,3].map(i=>`