Skip to content

Commit

Permalink
修正导出按日期排序
Browse files Browse the repository at this point in the history
  • Loading branch information
troilus committed Oct 30, 2024
1 parent b762f78 commit 52615fc
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -967,14 +967,19 @@
const todosByDate = JSON.parse(localStorage.getItem('todosByDate'));
let output = '';

for (const [date, todos] of Object.entries(todosByDate)) {
output += `## ${date}\n\n`;
todos.forEach(todo => {
const completedMarker = todo.completed ? '[x]' : '[ ]';
output += `- ${completedMarker} ${todo.text}\n`;
});
output += '\n'; // 添加空行以分隔日期
}
// 获取日期并排序
const sortedDates = Object.keys(todosByDate).sort((a, b) => new Date(a) - new Date(b));

// 遍历排序后的日期
for (const date of sortedDates) {
output += `## ${date}\n\n`;
const todos = todosByDate[date];
todos.forEach(todo => {
const completedMarker = todo.completed ? '[x]' : '[ ]';
output += `- ${completedMarker} ${todo.text}\n`;
});
output += '\n'; // 添加空行以分隔日期
}

const newTab = window.open();
newTab.document.write('<pre>' + output.trim() + '</pre>');
Expand Down

0 comments on commit 52615fc

Please sign in to comment.