anki/qt/aqt/data/web/js/reviewer-bottom.ts

55 lines
1.3 KiB
TypeScript
Raw Normal View History

2019-02-05 04:59:03 +01:00
/* Copyright: Ankitects Pty Ltd and contributors
* License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html */
2021-10-18 07:20:00 +02:00
/* eslint
@typescript-eslint/no-unused-vars: "off",
*/
let time: number; // set in python code
2019-12-18 04:27:39 +01:00
let maxTime = 0;
2021-04-13 19:28:03 +02:00
document.addEventListener("DOMContentLoaded", () => {
updateTime();
2020-06-24 13:54:38 +02:00
setInterval(function () {
time += 1;
2019-12-18 07:12:39 +01:00
updateTime();
}, 1000);
});
2021-04-13 19:28:03 +02:00
function updateTime(): void {
const timeNode = document.getElementById("time");
if (maxTime === 0) {
timeNode.textContent = "";
return;
}
time = Math.min(maxTime, time);
2019-12-18 04:27:39 +01:00
const m = Math.floor(time / 60);
const s = time % 60;
2021-04-13 19:28:03 +02:00
const sStr = String(s).padStart(2, "0");
const timeString = `${m}:${sStr}`;
2017-07-28 08:48:49 +02:00
if (maxTime === time) {
2021-04-13 19:28:03 +02:00
timeNode.innerHTML = `<font color=red>${timeString}</font>`;
} else {
2021-04-13 19:28:03 +02:00
timeNode.textContent = timeString;
}
2021-04-13 19:28:03 +02:00
}
2021-04-13 19:28:03 +02:00
function showQuestion(txt: string, maxTime_: number): void {
showAnswer(txt);
time = 0;
maxTime = maxTime_;
}
2021-04-13 19:28:03 +02:00
function showAnswer(txt: string): void {
document.getElementById("middle").innerHTML = txt;
}
2021-10-18 07:20:00 +02:00
function selectedAnswerButton(): string {
const node = document.activeElement as HTMLElement;
if (!node) {
return;
}
return node.dataset.ease;
}