MCPcopy Create free account
hub / github.com/dajie111/nodeseek-userscript / restoreLastSelectedNote

Function restoreLastSelectedNote

notes.js:1657–1696  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1655
1656 // 尝试恢复上次选择的笔记
1657 function restoreLastSelectedNote() {
1658 const lastSelected = getLastSelectedNote();
1659 if (!lastSelected) return false;
1660
1661 // 检查上次选择的分类是否存在
1662 const categories = readJSON(LS_KEYS.categories, []);
1663 const categoryExists = categories.some(c => c.id === lastSelected.categoryId);
1664 if (!categoryExists) return false;
1665
1666 // 检查上次选择的笔记是否存在
1667 const map = readJSON(LS_KEYS.notes, {});
1668 const list = map[lastSelected.categoryId] || [];
1669 const noteExists = list.some(n => n.id === lastSelected.noteId);
1670 if (!noteExists) return false;
1671
1672 // 切换到上次选择的分类
1673 if (currentCategoryId !== lastSelected.categoryId) {
1674 currentCategoryId = lastSelected.categoryId;
1675 window.currentCategoryId = currentCategoryId;
1676 renderCategories(); // 更新分类选择器
1677 }
1678
1679 // 选择上次的笔记
1680 const selectedNote = list.find(n => n.id === lastSelected.noteId);
1681 if (selectedNote) {
1682 currentNoteId = lastSelected.noteId;
1683 window.currentNoteId = currentNoteId;
1684 titleInput.value = selectedNote.title || '';
1685 editor.innerHTML = filterEditorContent(selectedNote.content || '');
1686 // 清除可能自动插入的<br>标签
1687 setTimeout(() => {
1688 if (editor.innerHTML === '<br>' || editor.innerHTML === '<br/>') {
1689 editor.innerHTML = '';
1690 }
1691 }, 10);
1692 return true;
1693 }
1694
1695 return false;
1696 }
1697
1698 function renderNotes() {
1699 noteList.innerHTML = '';

Callers 1

buildDialogFunction · 0.85

Calls 4

getLastSelectedNoteFunction · 0.85
readJSONFunction · 0.85
renderCategoriesFunction · 0.85
filterEditorContentFunction · 0.85

Tested by

no test coverage detected