Skip to content

Commit

Permalink
Try to fix #8
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jul 11, 2024
1 parent 9f9d8a6 commit 75ce453
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
25 changes: 12 additions & 13 deletions static/js/quiz.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$(document).ready(function () {
let currentQuestionIndex = 0;
const questions = questionsData || {};
const questionKeys = Object.keys(questions);
const questionsData = questions || {}; // Assuming questions is defined elsewhere
const questionKeys = Object.keys(questionsData);
const delayBetweenQuestions = 800;
const fadeDuration = 300;

Expand All @@ -19,20 +19,17 @@ $(document).ready(function () {
// Initialize question
function initializeQuestion() {
const currentKey = questionKeys[currentQuestionIndex];
const { source, translation } = questions[currentKey];

console.log("当前题目索引:", currentQuestionIndex);
console.log("当前键名:", currentKey);
Sentry.captureMessage(`Quiz, ${currentQuestionIndex}`);
const { source, translation } = questionsData[currentKey];

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

$inputBox.val("").attr("maxlength", translation.length);
createBoxes(translation.length);

$info.fadeIn(fadeDuration);
$info.fadeIn(fadeDuration, function() {
createBoxes(translation.length);
});
});
}

Expand All @@ -51,7 +48,7 @@ $(document).ready(function () {
function updateBoxes() {
const input = $inputBox.val();
const currentKey = questionKeys[currentQuestionIndex];
const { translation } = questions[currentKey];
const { translation } = questionsData[currentKey];

$(".box").each(function (index) {
const $box = $(this);
Expand All @@ -78,7 +75,7 @@ $(document).ready(function () {
const $summaryBody = $("#summaryBody").empty();

questionKeys.forEach((key) => {
const { source, translation } = questions[key];
const { source, translation } = questionsData[key];
$("<tr>").append(
$("<td>").text(source),
$("<td>").text(translation)
Expand All @@ -95,7 +92,7 @@ $(document).ready(function () {

const input = $(this).val();
const currentKey = questionKeys[currentQuestionIndex];
const { translation } = questions[currentKey];
const { translation } = questionsData[currentKey];

if (input === translation) {
$(".box").css("background-color", "#79b851");
Expand All @@ -104,7 +101,9 @@ $(document).ready(function () {
setTimeout(showSummary, delayBetweenQuestions);
} else {
currentQuestionIndex++;
setTimeout(initializeQuestion, delayBetweenQuestions);
setTimeout(() => {
initializeQuestion();
}, delayBetweenQuestions);
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion templates/quiz_sub.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
<script src="https://code.jquery.com/jquery-3.7.1.min.js"></script>
<script src="https://js-de.sentry-cdn.com/d2cad507d8a98e90f3325dbcda32791c.min.js" crossorigin="anonymous"></script>
<script>
const questionsData = {{ questions | tojson | safe }};
const questions = {{ questions | tojson | safe }};
const randomCode = "{{ random_code }}";
</script>
<script src="{{ url_for('static', filename='js/quiz.js') }}"></script>
Expand Down

0 comments on commit 75ce453

Please sign in to comment.