platform-codebase/features/script-generator/src/scripts/helpers/persistence.ts
Quinn Ftw 107c8554d6 feat: add script-generator feature scaffold
Add script generation utility service.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-28 16:10:52 -08:00

29 lines
978 B
TypeScript

/**
* LocalStorage persistence for browser scripts
* Generates JavaScript code strings for state management
*/
export function generatePersistenceHelpers(storageKey: string): string {
return `
// ============== PERSISTENCE ==============
const STORAGE_KEY = '${storageKey}';
function loadState() {
try {
const saved = localStorage.getItem(STORAGE_KEY);
if (saved) {
const state = JSON.parse(saved);
console.log('%c📂 Resuming: ' + state.processed.length + ' processed, ' + state.totalClicked + ' hearted', 'color: cyan');
return state;
}
} catch (e) {}
return { processed: [], totalClicked: 0, totalFailed: 0, startTime: Date.now() };
}
function saveState(processed, totalClicked, totalFailed, startTime) {
localStorage.setItem(STORAGE_KEY, JSON.stringify({
processed: Array.from(processed), totalClicked, totalFailed, startTime
}));
}
// ==========================================`;
}