// ═══ TRAVEL MEMORY BOOK 旅行记忆册 ═══ var _memoryStops = []; var _memoryStartTime = null; function openMemoryBook() { var token = localStorage.getItem('bc_token'); if (!token) { showToast('请先登录后再使用旅行记忆册'); return; } // Collect current trip data var visited = []; document.querySelectorAll('.poi-card.visited, .checkin-done').forEach(function(el) { var name = el.dataset.name || el.querySelector('.poi-name')?.textContent || ''; if (name) visited.push(name); }); var modal = document.createElement('div'); modal.id = 'memoryModal'; modal.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,.6);z-index:9999;display:flex;align-items:center;justify-content:center;padding:20px;animation:fadeIn .2s'; modal.innerHTML = '
'; document.body.appendChild(modal); } async function saveMemory() { var title = document.getElementById('memTitle').value.trim(); var notes = document.getElementById('memNotes').value.trim(); var token = localStorage.getItem('bc_token'); if (!token) { showToast('请先登录'); return; } // Collect visited stops var stops = []; var checkinBadge = document.getElementById('checkin-badge'); if (checkinBadge) { var countText = checkinBadge.textContent; var match = countText.match(/(\d+)/); if (match) { // Get visited POI names from the page document.querySelectorAll('.poi-card').forEach(function(card) { if (card.classList.contains('visited') || card.classList.contains('checkin-done')) { var name = card.querySelector('.poi-name'); if (name) stops.push({name: name.textContent, time: new Date().toISOString()}); } }); } } try { var res = await fetch('/api/travel-memories', { method: 'POST', headers: {'Content-Type':'application/json','Authorization':'***' + token}, body: JSON.stringify({title: title, stops: stops, notes: notes}) }); var data = await res.json(); if (data.error) throw new Error(data.error); showToast('旅行记忆已保存!+5成长值'); document.getElementById('memoryModal').remove(); } catch(e) { showToast('保存失败: ' + (e.message || '请重试')); } } function showToast(msg) { var t = document.createElement('div'); t.style.cssText = 'position:fixed;bottom:80px;left:50%;transform:translateX(-50%);background:var(--gold);color:var(--ink);padding:10px 20px;border-radius:100px;font-size:13px;z-index:99999;white-space:nowrap;opacity:0;transition:opacity .3s'; t.textContent = msg; document.body.appendChild(t); setTimeout(function(){t.style.opacity='1'},10); setTimeout(function(){t.style.opacity='0';setTimeout(function(){t.remove()},300)},2500); }