Add script generation utility service. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
29 lines
978 B
TypeScript
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
|
|
}));
|
|
}
|
|
// ==========================================`;
|
|
}
|