Skip to content

Commit 6254778

Browse files
committed
Fix: showtoast only for web side && modify review time caculate format
1 parent b015b9e commit 6254778

File tree

2 files changed

+47
-25
lines changed

2 files changed

+47
-25
lines changed

src/popup/daily-review.js

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,16 @@ export function updateCardLimitDisplay() {
341341
});
342342
}
343343

344+
// 更新卡片显示
345+
export function updateCardDisplay() {
346+
console.log('更新卡片显示');
347+
348+
updateStats(); // 更新统计信息,传递当前显示的卡片数量
349+
350+
createReviewCards(); // 创建新的卡片
351+
}
352+
353+
344354

345355

346356
// 改变卡片数量
@@ -361,14 +371,6 @@ export async function changeCardLimit(delta) {
361371
}
362372

363373

364-
// 更新卡片显示
365-
export function updateCardDisplay() {
366-
console.log('更新卡片显示');
367-
368-
updateStats(); // 更新统计信息,传递当前显示的卡片数量
369-
370-
createReviewCards(); // 创建新的卡片
371-
}
372374

373375

374376
// 标记题目为已复习
@@ -396,7 +398,7 @@ async function markAsReviewed(button, problem) {
396398

397399

398400
// 更新统计信息
399-
updateStats();
401+
updateCardDisplay();
400402
console.log('更新完成');
401403
}
402404

@@ -440,16 +442,30 @@ function createReviewCards() {
440442
// 设置下次复习时间
441443
const nextReviewTips = fsrsState.nextReview
442444
? (() => {
443-
const msUntilReview = new Date(fsrsState.nextReview) - new Date();
444-
const daysUntilReview = Math.ceil(msUntilReview / (1000 * 60 * 60 * 24));
445+
const nextReviewDate = new Date(fsrsState.nextReview);
446+
const now = new Date();
445447

446-
if (msUntilReview >= 0 && msUntilReview <= 24 * 60 * 60 * 1000) {
447-
return 'Review today'; // 24小时内需要复习
448-
} else if (daysUntilReview > 0) {
449-
return `Review in ${daysUntilReview} day${daysUntilReview > 1 ? 's' : ''}`;
450-
} else {
451-
const daysOverdue = Math.abs(daysUntilReview);
448+
// 获取当前日期和下次复习日期(不含时间)
449+
const today = new Date(now.getFullYear(), now.getMonth(), now.getDate());
450+
const reviewDay = new Date(nextReviewDate.getFullYear(), nextReviewDate.getMonth(), nextReviewDate.getDate());
451+
452+
// 计算日期差(天数)
453+
const diffTime = reviewDay.getTime() - today.getTime();
454+
const diffDays = Math.round(diffTime / (1000 * 60 * 60 * 24));
455+
456+
if (diffDays < 0) {
457+
// 已经过了计划复习日期
458+
const daysOverdue = Math.abs(diffDays);
452459
return `Delay by ${daysOverdue} day${daysOverdue > 1 ? 's' : ''}`;
460+
} else if (diffDays === 0) {
461+
// 今天需要复习
462+
return 'Review today';
463+
} else if (diffDays === 1) {
464+
// 明天需要复习
465+
return 'Review tomorrow';
466+
} else {
467+
// x天后复习
468+
return `Review in ${diffDays} days`;
453469
}
454470
})()
455471
: 'Not scheduled';

src/popup/script/submission.js

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ export const addRecordButton = () => {
184184
// 抽取成通用的处理函数
185185
export async function handleFeedbackSubmission(problem = null) {
186186
try {
187+
// 记录是否为页面提交
188+
const isPageSubmission = !problem;
189+
187190
// 显示难度反馈弹窗
188191
const feedback = await showDifficultyFeedbackDialog().catch(error => {
189192
console.log(error); // "用户取消评分"
@@ -226,14 +229,17 @@ export async function handleFeedbackSubmission(problem = null) {
226229
problem = updateProblemWithFSRS(problem, feedback);
227230
await createOrUpdateProblem(problem);
228231

229-
// 计算下次复习时间与今天的天数差
230-
const nextReviewDate = new Date(problem.fsrsState.nextReview);
231-
const today = new Date();
232-
const diffTime = nextReviewDate.getTime() - today.getTime();
233-
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
232+
// 只有在页面提交时才显示成功提示
233+
if (isPageSubmission) {
234+
// 计算下次复习时间与今天的天数差
235+
const nextReviewDate = new Date(problem.fsrsState.nextReview);
236+
const today = new Date();
237+
const diffTime = nextReviewDate.getTime() - today.getTime();
238+
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
234239

235-
// 显示复习成功提示,包含下次复习时间
236-
showToast(`复习成功!下次复习时间:${nextReviewDate.toLocaleDateString()}${diffDays}天后)\nReview successful! Next review: ${nextReviewDate.toLocaleDateString()} (in ${diffDays} days)`, "success");
240+
// 显示复习成功提示,包含下次复习时间
241+
showToast(`复习成功!下次复习时间:${nextReviewDate.toLocaleDateString()}${diffDays}天后)\nReview successful! Next review: ${nextReviewDate.toLocaleDateString()} (in ${diffDays} days)`, "success");
242+
}
237243

238244
await syncProblems(); // 同步到云端
239245
console.log("提交成功!");
@@ -245,7 +251,7 @@ export async function handleFeedbackSubmission(problem = null) {
245251
}
246252

247253
// 添加一个更醒目的提示框函数,支持不同类型的提示
248-
function showToast(message, type = "info", duration = 5000) {
254+
function showToast(message, type = "info", duration = 4000) {
249255
// 检查是否已存在toast样式
250256
if (!document.getElementById('lms-toast-style')) {
251257
const style = document.createElement('style');

0 commit comments

Comments
 (0)