setConf("MAX_WEBSOCKET_ERRORS", 1);
setConf("APP_PATH", "");
setConf("ENABLE_SPELL_CHECKER", false);
+ setConf("DOUBLE_TAP_DURATIONS", [650, 1100, 1800, 3000, 5000]);
+ setConf("FLASH_LIGHT_DURATIONS", [800, 1600, 3200]);
+ setConf("FLASH_LIGHT_COLOR", "#E3E");
+ setConf("ENABLE_TIMER", true);
const _ = (window.libD && libD.l10n) ? libD.l10n() : function (s) {
return s;
}
}
+ function translateDuration(x, values) {
+ if (x < 0) {
+ return null;
+ }
+
+ if (x < values.length) {
+ return values[Math.floor(x)];
+ }
+
+ for (let i = 0; i < values.length; i++) {
+ if (x <= values[i]) {
+ return i;
+ }
+ }
+ return values.length - 1;
+ }
+
+ function initLaserPointer() {
+ document.body.addEventListener("dblclick", laserDblClick);
+ document.body.addEventListener("touchstart", laserTouch);
+
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "doubleTapDuration")) {
+ localStorage.doubleTapDuration = Conf.DOUBLE_TAP_DURATIONS[Math.floor(Conf.DOUBLE_TAP_DURATIONS.length / 2)];
+ }
+ const doubleTapDuration = document.getElementById("double-tap-duration");
+ if (doubleTapDuration) {
+ doubleTapDuration.max = Conf.DOUBLE_TAP_DURATIONS.length - 1;
+ doubleTapDuration.value = translateDuration(localStorage.doubleTapDuration, Conf.DOUBLE_TAP_DURATIONS);
+ doubleTapDuration.onchange = function () {
+ localStorage.doubleTapDuration = translateDuration(
+ document.getElementById("double-tap-duration").value,
+ Conf.DOUBLE_TAP_DURATIONS
+ );
+ };
+ }
+
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "flashLightDuration")) {
+ localStorage.flashLightDuration = Conf.FLASH_LIGHT_DURATIONS[Math.floor(Conf.FLASH_LIGHT_DURATIONS.length / 2)];
+ }
+ const flashLightDuration = document.getElementById("flash-light-duration");
+ if (flashLightDuration) {
+ flashLightDuration.max = Conf.FLASH_LIGHT_DURATIONS.length - 1;
+ flashLightDuration.value = translateDuration(localStorage.flashLightDuration, Conf.FLASH_LIGHT_DURATIONS);
+ flashLightDuration.onchange = function () {
+ localStorage.flashLightDuration = translateDuration(
+ document.getElementById("flash-light-duration").value,
+ Conf.FLASH_LIGHT_DURATIONS
+ );
+ };
+ }
+
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "flashLightColor")) {
+ localStorage.flashLightColor = Conf.FLASH_LIGHT_COLOR;
+ }
+ const flashLightColor = document.getElementById("flash-light-color");
+ if (flashLightColor) {
+ flashLightColor.value = localStorage.flashLightColor;
+ flashLightColor.onchange = function () {
+ localStorage.flashLightColor = document.getElementById("flash-light-color").value;
+ const style = document.createElement("style");
+ style.textContent = ".laser-highlight {background-color: " + localStorage.flashLightColor + ";}";
+ document.body.appendChild(style);
+ };
+ flashLightColor.onchange();
+ }
+ }
+
+ function timerString(delta) {
+ const d = Math.floor(delta / (60 * 60 * 24));
+ const h = Math.floor((delta % (60 * 60 * 24)) / (60 * 60));
+ const m = Math.floor((delta % (60 * 60)) / 60);
+ const s = Math.floor(delta % 60);
+ return ((d > 0) ? format(_("{0}d "), d) : "") +
+ ((h > 0) ? format(_("{0}h "), h) : "") +
+ format(_("{0}' {1}''"), m, s);
+ }
+
+ function timerDate() {
+ return Math.floor(Date.now() / 1000);
+ }
+
+ function initTimer() {
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerTurnDate")) {
+ localStorage.timerTurnDate = timerDate();
+ }
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerGlobalDate")) {
+ localStorage.timerGlobalDate = timerDate();
+ }
+ if (!Object.prototype.hasOwnProperty.call(localStorage, "timerEnable")) {
+ localStorage.timerEnable = Conf.ENABLE_TIMER;
+ }
+ document.getElementById("enable-timer").onclick = function () {
+ setTimerState(document.getElementById("enable-timer").checked);
+ };
+ setTimerState(localStorage.timerEnable);
+ }
+
+ function setTimerState(state) {
+ if (state) {
+ document.getElementById("timer").style.display = "block";
+ document.getElementById("enable-timer").checked = true;
+ localStorage.timer = setInterval(function () {
+ document.getElementById("timer-turn").textContent = timerString(timerDate() - Number(localStorage.timerTurnDate));
+ document.getElementById("timer-global").textContent = timerString(timerDate() - Number(localStorage.timerGlobalDate));
+ }, 1000);
+ } else {
+ document.getElementById("timer").style.display = "none";
+ document.getElementById("enable-timer").checked = false;
+ if (Object.prototype.hasOwnProperty.call(localStorage, "timer")) {
+ clearInterval(localStorage.timer);
+ delete localStorage.timer;
+ }
+ localStorage.timerGlobalDate = localStorage.timerTurnDate = timerDate();
+ }
+ }
+
function repromptName(f) {
if (localStorage.trivabblePlayerName && localStorage.trivabblePlayerName.trim()) {
f();
initGame();
initSound();
initSpellChecker();
+ initLaserPointer();
+ initTimer();
};
trivabble.l10nError = trivabble.run;