<meta charset="utf-8">
<title>JSChessClock</title>
<script src="script.js"></script>
- <!--<link rel="stylesheet" type="text/css" href="style.css" />-->
+ <link rel="stylesheet" type="text/css" href="style.css" id="style" />
</head>
<body onload="init()" onresize="fitscreen()">
- <h1>JSChessClock</h1>
-
<div class="clock-container">
<svg version="1.1" width="650" height="500"
xmlns="http://www.w3.org/2000/svg">
- <path id="left-button-top" class="button-long" fill="#c0c0c0"
+ <path id="left-button-top" class="button-long" fill="#c0c0c0"
d="M 210 70 A 140 140 0 0 0 30 70 Z" stroke="#c0c0c0"
onclick="toggle()" cursor="pointer" />
<rect id="left-button-body" class="button-long" x="60" y="70"
</div>
<div class="timer" id="timer-right">15:00</div>
</div>
+ <h1>JSChessClock</h1>
<div class="commands">
<div class="cmd" onclick="setTime();">[S]et time</div>
<div class="cmd" onclick="reset();">[R]eset to previous</div>
var flagelem = document.getElementById(flagid);
flagelem.style.visibility = time <= 0 ? "visible" : "hidden";
};
+
+ var startTickingUnixTime = null;
+ var remainingTimeAtTickingStart = null;
+
var thisTimer = this; // workaround to use this in setInterval
this.tick = function() {
- time -= (precision <= time ? precision : time);
+ var currentPassedTime = new Date() - startTickingUnixTime;
+ time = remainingTimeAtTickingStart - currentPassedTime;
if(time <= 0) {
+ time = 0;
// time's up
clearInterval(intervalID);
thisTimer.isTicking = false;
outputTime();
};
this.start = function() {
+ startTickingUnixTime = new Date();
+ remainingTimeAtTickingStart = time;
intervalID = setInterval(this.tick, precision);
this.isTicking = true;
};
var rbt = document.getElementById('right-button-top');
var rbt_d = rbt.getAttribute('d').split(' ');
var rbb = document.getElementById('right-button-body');
-
+
var y_diff = 50 * (leftIsLong ? 1 : -1);
var classes = ['button-short', 'button-long'];
rbb.setAttribute('class', classes[(leftIsLong + 1) % 2]);
lbt.setAttribute('d', lbt_d.join(' '));
rbt.setAttribute('d', rbt_d.join(' '));
-
+
lbt.setAttribute('onclick', leftIsLong ? '' : 'toggle()');
lbb.setAttribute('onclick', leftIsLong ? '' : 'toggle()');
lbt.setAttribute('cursor', leftIsLong ? 'default' : 'pointer');
var leftstart, rightstart;
var def = timeToTimeStr(currentTimers.leftTimer.getDefaultTime());
var regex = /[0-9][0-9]:[0-5][0-9]/;
-
+
leftstart = prompt("Time for LEFT player in MM:SS", def);
if(leftstart === null) return; // Cancel
while(!leftstart.match(regex)) {
function init() {
insertcss();
- setTimeout(fitscreen, 5); // hack to allow DOM to be redrawn with new css
+ setTimeout(fitscreen, 2000); // hack to allow DOM to be redrawn with new css
}
function fitscreen() {
*/
var heightRatio = window.innerHeight / document.body.scrollHeight;
var widthRatio = window.innerWidth / document.body.scrollWidth;
- var scaleRatio = Math.min(heightRatio, widthRatio);
+ var scaleRatio = Math.min(heightRatio, widthRatio, 1);
document.body.style.transform = 'scale(' + scaleRatio + ')';
}
function insertcss() {
/* fix positions for browsers that don't support flex */
- var cssfile = document.createElement("link");
- cssfile.setAttribute("rel", "stylesheet");
- cssfile.setAttribute("type", "text/css");
- if('align-items' in document.body.style) {
- cssfile.setAttribute("href", "style.css");
- } else {
+ var cssfile = document.getElementById("style");
+ if(!('align-items' in document.body.style)) {
cssfile.setAttribute("href", "noflex.css");
}
- document.head.appendChild(cssfile);
}