|
$(document).ready(function() { |
|
var audio = new Audio("http://www.universal-soundbank.com/802a/805020000000000000000000000pkjn800000000000000000000000000000090/g/85055050505050505050505/k/4202.MP3"); |
|
audio.volume=0.5; |
|
var workSeconds = 1500; |
|
var funSeconds = 300; |
|
var switcher = true; |
|
|
|
var Clock = { |
|
totalSeconds: 0, |
|
changeW: function(){ |
|
var min = Math.floor(workSeconds / 60 % 60); |
|
return min; |
|
}, |
|
changeF: function(){ |
|
var min = Math.floor(funSeconds / 60 % 60); |
|
return min; |
|
}, |
|
start: function() { |
|
var self = this; |
|
if(self.totalSeconds === 0){ |
|
self.totalSeconds = workSeconds; |
|
} |
|
this.interval = setInterval(function() { |
|
if (self.totalSeconds > 0) { |
|
self.totalSeconds -= 1; |
|
} else { |
|
audio.play(); |
|
if (switcher===true) { |
|
$("body").css("background","#9b59b6"); |
|
$(".info").text("Relax.."); |
|
self.totalSeconds = funSeconds; |
|
switcher = false; |
|
} else { |
|
$("body").css("background","#3498db"); |
|
$(".info").text("Work!"); |
|
self.totalSeconds = workSeconds; |
|
switcher = true; |
|
} |
|
} |
|
var sec = (self.totalSeconds % 60); |
|
var min = Math.floor(self.totalSeconds / 60 % 60); |
|
|
|
if (sec < 10) { |
|
sec = "0" + sec; |
|
} |
|
if (min < 10) { |
|
min = "0" + min; |
|
} |
|
$(".clock").text(min + " : " + sec); |
|
}, 1000); |
|
}, |
|
|
|
pause: function() { |
|
clearInterval(this.interval); |
|
delete this.interval; |
|
}, |
|
resume: function() { |
|
if (!this.interval) { |
|
this.start(); |
|
} |
|
} |
|
}; |
|
$('#pause').click(function() { |
|
Clock.pause(); |
|
$("#pause").hide(); |
|
$("#start").show(); |
|
}); |
|
$('#start').click(function() { |
|
if(Clock.totalSeconds === 0){ |
|
$("body").css("background","#3498db"); |
|
$(".info").text("Work!"); |
|
} |
|
Clock.resume(); |
|
$(".tog").toggle(); |
|
$("#start").text("Resume"); |
|
$(".tog2").css("display", "none"); |
|
$(".hello").css("display","block"); |
|
}); |
|
$('#addW').click(function() { |
|
workSeconds += 60; |
|
$("#minW").text(Clock.changeW); |
|
}); |
|
$('#subW').click(function() { |
|
if (workSeconds > 60) { |
|
workSeconds -= 60; |
|
} |
|
$("#minW").text(Clock.changeW); |
|
}); |
|
$('#addF').click(function() { |
|
funSeconds += 60; |
|
$("#minF").text(Clock.changeF); |
|
}); |
|
$('#subF').click(function() { |
|
if (funSeconds > 60) { |
|
funSeconds -= 60; |
|
} |
|
$("#minF").text(Clock.changeF); |
|
}); |
|
$("#stop").click(function(){ |
|
Clock.pause(); |
|
$(".clock").text("-- : --"); |
|
$(".hello").css("display","none"); |
|
$(".tog2").css("display", "block"); |
|
if($("#start").css('display') == 'none'){ |
|
$(".tog").toggle(); |
|
} |
|
$("#start").text("Start"); |
|
workSeconds = $("#minW").text() * 60; |
|
funSeconds = $("#minF").text() * 60; |
|
Clock.totalSeconds = 0; |
|
$("body").css("background","#2ecc71"); |
|
$(".info").text(""); |
|
}); |
|
$(".tag").click(function(){ |
|
$(".tag").toggle(); |
|
}); |
|
$(".fa-volume-up").click(function(){ |
|
audio.muted = true; |
|
}); |
|
$(".fa-volume-off").click(function(){ |
|
audio.muted = false; |
|
}); |
|
}); |