Skip to content

Commit

Permalink
Revert changes since #8 cannot be fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jul 13, 2024
1 parent 61dbb85 commit 296da62
Showing 1 changed file with 15 additions and 21 deletions.
36 changes: 15 additions & 21 deletions static/js/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,34 +16,28 @@ $(document).ready(function () {
const $inputBox = $("#inputBox");
const $boxes = $("#boxes");

function showQuestion() {
function initializeQuestion() {
const currentKey = questionKeys[currentQuestionIndex];
const { source, translation } = questionsData[currentKey];
const translationSegments = [...new Intl.Segmenter().segment(translation)].map(segment => segment.segment);
const translationLength = translationSegments.length;

console.log("当前题目索引:", currentQuestionIndex);
console.log("当前键名:", currentKey);
Sentry.captureMessage(`Quiz, ${currentQuestionIndex}`);

$sourceText.text(source);
$keyText.text(currentKey);
$inputBox.val("");
createBoxes(translationLength);
}
const translationSegments = [...new Intl.Segmenter().segment(translation)].map(segment => segment.segment);
const translationLength = translationSegments.length;

function fadeTransition(callback) {
$info.fadeOut(fadeDuration, function () {
if (callback) callback();
$sourceText.text(source);
$keyText.text(currentKey);

$inputBox.val("");
createBoxes(translationLength);

$info.fadeIn(fadeDuration);
});
}

function nextQuestion() {
currentQuestionIndex++;
fadeTransition(showQuestion);
}

function getSegmentedText(text) {
return [...new Intl.Segmenter().segment(text)].map(segment => segment.segment);
}
Expand All @@ -67,6 +61,7 @@ $(document).ready(function () {
const input = $inputBox.val();
const currentKey = questionKeys[currentQuestionIndex];
const { translation } = questionsData[currentKey];

const translationSegments = getSegmentedText(translation);
const translationLength = translationSegments.length;

Expand Down Expand Up @@ -139,19 +134,18 @@ $(document).ready(function () {
$(".box").css("background-color", "#79b851");

if (currentQuestionIndex === questionKeys.length - 1) {
setTimeout(function () {
showSummary();
}, delayBetweenQuestions);
setTimeout(showSummary, delayBetweenQuestions);
} else {
setTimeout(function () {
nextQuestion();
currentQuestionIndex++;
setTimeout(() => {
initializeQuestion();
}, delayBetweenQuestions);
}
}
});

// Initialize first question
fadeTransition(showQuestion);
initializeQuestion();
});

$(document).ready(function () {
Expand Down

0 comments on commit 296da62

Please sign in to comment.