Skip to content

Commit

Permalink
What's happening
Browse files Browse the repository at this point in the history
  • Loading branch information
SkyEye-FAST committed Jul 12, 2024
1 parent a7d19a4 commit 185c2b8
Showing 1 changed file with 29 additions and 7 deletions.
36 changes: 29 additions & 7 deletions static/js/quiz.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ $(document).ready(function () {

function initializeQuestion() {
const currentKey = questionKeys[currentQuestionIndex];
const source = questionsData[currentKey] && questionsData[currentKey].source;
const translation = questionsData[currentKey] && questionsData[currentKey].translation;
const { source, translation } = questionsData[currentKey];

console.log("当前题目索引:", currentQuestionIndex);
console.log("当前键名:", currentKey);
Expand Down Expand Up @@ -61,7 +60,7 @@ $(document).ready(function () {
function updateBoxes() {
const input = $inputBox.val();
const currentKey = questionKeys[currentQuestionIndex];
const translation = questionsData[currentKey] && questionsData[currentKey].translation;
const { translation } = questionsData[currentKey];

const translationSegments = getSegmentedText(translation);
const translationLength = translationSegments.length;
Expand Down Expand Up @@ -97,9 +96,7 @@ $(document).ready(function () {
const $summaryBody = $("#summaryBody").empty();

questionKeys.forEach((key) => {
const source = questionsData[key] && questionsData[key].source;
const translation = questionsData[key] && questionsData[key].translation;

const { source, translation } = questionsData[key];
$("<tr>").append(
$("<td>").text(source),
$("<td>").text(translation)
Expand All @@ -126,7 +123,7 @@ $(document).ready(function () {
const currentIndex = currentQuestionIndex;

const currentKey = questionKeys[currentIndex];
const translation = questionsData[currentKey] && questionsData[currentKey].translation;
const { translation } = questionsData[currentKey];

if (!isComposing) {
const translationLength = getSegmentedText(translation).length;
Expand All @@ -151,4 +148,29 @@ $(document).ready(function () {

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

$(document).ready(function () {
var currentUrl = window.location.href;
var match = currentUrl.match(/\/([^\/?#]+)[\/?#]?$/);
var lastSegment = match ? match[1] : "";
document.getElementById("last-segment").textContent = lastSegment;

$("#copy-button").click(function () {
var $copyButton = $(this);
var $lastSegment = $("#last-segment");
var lastSegmentContent = $lastSegment.text();

navigator.clipboard
.writeText(lastSegmentContent)
.then(function () {
$copyButton.text("check");
setTimeout(function () {
$copyButton.text("content_copy");
}, 1500);
})
.catch(function (err) {
console.error("Failed to copy: ", err);
});
});
});

0 comments on commit 185c2b8

Please sign in to comment.