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

Function restoreToVersion

notes.js:2217–2271  ·  view source on GitHub ↗
(historyItem)

Source from the content-addressed store, hash-verified

2215
2216 // 恢复到指定版本
2217 function restoreToVersion(historyItem) {
2218 if (!currentNoteId) return;
2219
2220 const map = readJSON(LS_KEYS.notes, {});
2221 const list = map[currentCategoryId] || [];
2222 const noteIndex = list.findIndex(n => n.id === currentNoteId);
2223
2224 if (noteIndex === -1) return;
2225
2226 const note = list[noteIndex];
2227
2228 // 保存当前版本到历史记录
2229 if (!note.history) note.history = [];
2230 note.history.unshift({
2231 title: note.title,
2232 content: note.content,
2233 timestamp: note.updatedAt || Date.now()
2234 });
2235
2236 // 限制历史记录数量为30个
2237 if (note.history.length > 30) {
2238 note.history = note.history.slice(0, 30);
2239 }
2240
2241 // 恢复到历史版本
2242 note.title = historyItem.title;
2243 note.content = historyItem.content;
2244 note.updatedAt = Date.now();
2245
2246 // 更新编辑器显示
2247 titleInput.value = note.title || '';
2248 editor.innerHTML = filterEditorContent(note.content || '');
2249 // 清除可能自动插入的<br>标签
2250 setTimeout(() => {
2251 if (editor.innerHTML === '<br>' || editor.innerHTML === '<br/>') {
2252 editor.innerHTML = '';
2253 }
2254 }, 10);
2255
2256 // 保存到localStorage
2257 map[currentCategoryId] = list;
2258 writeJSON(LS_KEYS.notes, map);
2259
2260 // 重新渲染笔记列表
2261 renderNotes();
2262
2263 // 更新保存状态
2264 updateSaveState();
2265
2266 // 更新按钮文本
2267 updateButtonTexts();
2268
2269 // 显示恢复成功提示
2270 showRestoreNotification();
2271 }
2272
2273 // 显示恢复成功提示
2274 function showRestoreNotification() {

Callers 1

showHistoryDialogFunction · 0.85

Calls 7

readJSONFunction · 0.85
filterEditorContentFunction · 0.85
writeJSONFunction · 0.85
renderNotesFunction · 0.85
updateSaveStateFunction · 0.85
updateButtonTextsFunction · 0.85
showRestoreNotificationFunction · 0.85

Tested by

no test coverage detected