aboutsummaryrefslogtreecommitdiff
path: root/beamer/viewer/screen/timer.js
diff options
context:
space:
mode:
Diffstat (limited to 'beamer/viewer/screen/timer.js')
-rw-r--r--beamer/viewer/screen/timer.js48
1 files changed, 48 insertions, 0 deletions
diff --git a/beamer/viewer/screen/timer.js b/beamer/viewer/screen/timer.js
new file mode 100644
index 0000000..a04ea63
--- /dev/null
+++ b/beamer/viewer/screen/timer.js
@@ -0,0 +1,48 @@
1/*
2 * Beamer Viewer, a web-based PDF presentation viewer
3 * Copyright (C) 2018 Pacien TRAN-GIRARD
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as
7 * published by the Free Software Foundation, either version 3 of the
8 * License, or (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
19"use strict";
20
21class Timer {
22 constructor(window) {
23 this.display = window.document.getElementById("timer");
24 this.startTime = null;
25 this._setDisplay(0);
26 }
27
28 start() {
29 if (this.startTime != null) return;
30 this.startTime = Date.now();
31
32 const self = this;
33 setInterval(function() {
34 self._runTimer();
35 }, 1000);
36 }
37
38 _runTimer() {
39 const timeDelta = Math.floor((Date.now() - this.startTime) / 1000);
40 this._setDisplay(timeDelta);
41 }
42
43 _setDisplay(seconds) {
44 const dateObj = new Date(null);
45 dateObj.setSeconds(seconds);
46 this.display.textContent = dateObj.toISOString().substr(11, 8);
47 }
48}