JSFiddle - React, Tailwind, and code Playground
HTML
<body id="body">
<a href="http://www.google.co.in" id="fr" target="_blank">Eureka! She's Alive!!</a>
<div class="fixedlayout">
<button id="startButton" onclick="start(3)">Start</button>
<div id="CanvasDiv">
</div>
</div>
<script>
var minutes = 0;
var running = false;
function start(paramMn) {
minutes = paramMn;
if (minutes > 0) {
showCircle(minutes);
running = true;
setTimeout(update, 1000);
}
}
function stop() {
clearTimeout(update);
running = false;
}
function update()
{
if (!running) return;
minutes--;
showCircle(minutes);
if (running) {
if (minutes > 0) {
setTimeout(update, 1000);
}
else {
document.getElementById("fr").click();
running = false;
}
}
}
function Timer(duration /* in ms */ , props) {
this.ontick = props && typeof props.ontick === "function" ? props.ontick : function() {};
this.onend = props && typeof props.onend === "function" ? props.onend : function() {};
this.interval = props && typeof props.interval === "number" ? props.interval : 1000 / 10;
this.elapsed = 0;
var running = false,
start, end, self = this;
this.start = function() {
if (running) return self;
start = new Date().getTime();
end = start + duration;
tick();
running = true;
return self;
};
function tick() {
var now = new Date().getTime();
self.ontick.call(self);
self.elapsed = now - start;
if (now < end) setTimeout(tick, self.interval);
else self.onend.call(self);
}
}
function showCircle(minutes){
var can = document.createElement("canvas"),
ctx = can.getContext('2d'),
sta = -Math.PI / 2,
dur = 1 * 1000;
can.width = 800;
can.height = 800;
document.body.removeChild(document.body.lastChild);
document.body.appendChild(can);
ctx.font = "normal 30px Arial";
var myTimer = new Timer(dur, {
ontick: function () {
var pct =...