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

Function restoreNoteFromTrash

notes.js:4030–4065  ·  view source on GitHub ↗
(trashIndex)

Source from the content-addressed store, hash-verified

4028
4029 // 从回收站恢复笔记
4030 function restoreNoteFromTrash(trashIndex) {
4031 const trashData = readJSON(LS_KEYS.trash, []);
4032 if (trashIndex < 0 || trashIndex >= trashData.length) {
4033 alert('找不到要恢复的笔记');
4034 return;
4035 }
4036
4037 const trashNote = trashData[trashIndex];
4038 const { deletedAt, originalCategoryId, originalCategoryName, ...noteData } = trashNote;
4039
4040 // 检查原分类是否还存在
4041 const categories = readJSON(LS_KEYS.categories, []);
4042 const categoryExists = categories.some(c => c.id === originalCategoryId);
4043
4044 let targetCategoryId = originalCategoryId;
4045 if (!categoryExists) {
4046 // 原分类不存在,恢复到默认分类
4047 targetCategoryId = 'default';
4048 alert(`原分类"${originalCategoryName}"已不存在,笔记将恢复到默认分类`);
4049 }
4050
4051 // 恢复笔记到目标分类
4052 const map = readJSON(LS_KEYS.notes, {});
4053 if (!map[targetCategoryId]) {
4054 map[targetCategoryId] = [];
4055 }
4056 map[targetCategoryId].unshift(noteData);
4057 writeJSON(LS_KEYS.notes, map);
4058
4059 // 从回收站移除
4060 trashData.splice(trashIndex, 1);
4061 writeJSON(LS_KEYS.trash, trashData);
4062
4063 // 已成功恢复,不再弹窗打断用户
4064 // alert(`笔记"${noteData.title || '未命名'}"已成功恢复`);
4065 }
4066
4067 // 永久删除笔记
4068 function permanentDeleteNote(trashIndex) {

Callers 1

showTrashDialogFunction · 0.85

Calls 2

readJSONFunction · 0.85
writeJSONFunction · 0.85

Tested by

no test coverage detected