guanghulab/modules/m-channel/channel-state.js
Guanghu Domestic Migration d1e47f4565
Some checks are pending
自动更新代码和重启 / update-and-restart (push) Waiting to run
CI检查 + 自动部署 / check (push) Waiting to run
CI检查 + 自动部署 / deploy (push) Blocked by required conditions
重启聊天服务 / restart (push) Waiting to run
chore: import sanitized domestic snapshot for REPO-002
Source snapshot: ca48d3ddf926d79aa138306164169baf764bb829
2026-07-17 15:54:41 +08:00

45 lines
1.2 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 状态管理localStorage
window.ChannelState = {
STORAGE_KEY: 'hololake_channel_state',
// 保存状态
saveState: function(state) {
const data = {
...state,
timestamp: Date.now(),
visited: state.visited || []
};
localStorage.setItem(this.STORAGE_KEY, JSON.stringify(data));
console.log('[state] 保存状态:', data);
},
// 恢复状态
restoreState: function() {
const saved = localStorage.getItem(this.STORAGE_KEY);
if (!saved) return null;
try {
const state = JSON.parse(saved);
console.log('[state] 恢复状态:', state);
return state;
} catch (e) {
console.error('[state] 解析失败:', e);
return null;
}
},
// 标记已访问
markVisited: function(channel) {
const state = this.restoreState() || { visited: [] };
if (!state.visited.includes(channel)) {
state.visited.push(channel);
this.saveState(state);
}
},
// 清除状态
clearState: function() {
localStorage.removeItem(this.STORAGE_KEY);
console.log('[state] 已清除');
}
};