<body>
<p>Pomodoro</p>
<div id="Mytimer"><p><a id="timer" href="javascript:tiktak()">count!</a></p>
<p><input type="text" id="volume" value="3" />vol</p>
</div>
<input type="button" value="+" onClick="inc()">
<input type="button" value="-" onClick="dec()">
<script>
var ch = document.getElementById("volume").value; //??? не работает!!!
function inc(){ch++;document.getElementById("volume").value = ch;}
function dec(){ch--;document.getElementById("volume").value = ch;}
var minute = ch;
var second = minute * 60;
function tiktak(){
if(second >= 60){
minute = Math.floor(second/60);}
var sec = second - minute*60;
if(second<60){minute = 0;}
if(minute<=9){minute = "0" + minute;}
if(second<=9){sec = "0" + sec;}
if(document.getElementById){timer.innerHTML = minute + ":" + sec;}
if(second==00){return false;}
second--;
setTimeout("tiktak()", 1000);
}
</script>
</body>
<p>Pomodoro</p>
<div id="Mytimer">
<p><a href="" id="timer">count!</a>
</p>
<p>
<input type="text" id="volume" value="3" />vol</p>
</div>
<input type="button" value="+">
<input type="button" value="-">
var d = document;
d.addEventListener('DOMContentLoaded', function () {
var inp = d.getElementById('volume'),
out = d.getElementById('timer'),
min = 0, seconds = inp.value * 60, timer;
[].forEach.call(d.querySelectorAll('[type=button]'), function (but) {
but.addEventListener('click', function () {
inp.value -= -(this.value + '1');
(inp.value <= 0) && (inp.value = 0);
}, false);
});
out.addEventListener('click', function (e) {
e.preventDefault();
seconds = inp.value * 60;
clearTimeout(timer);
tiktak();
}, false);
function tiktak() {
seconds--;
if (seconds <= 0) {
out.textContent = 'Finish!';
clearTimeout(timer);
return false;
}
min = Math.floor(seconds / 60);
out.textContent = ('0' + min).slice(-2) + ':' + ('0' + (seconds - min * 60)).slice(-2);
timer = setTimeout(tiktak, 1000);
}
}, false);