|
1 | | -// ScriptVault v2.0.0 - Background Service Worker |
| 1 | +// ScriptVault v2.0.1 - Background Service Worker |
2 | 2 | // Comprehensive userscript manager with cloud sync and auto-updates |
3 | 3 | // NOTE: This file is built from source modules. Edit the individual files in |
4 | 4 | // shared/, modules/, and lib/, then run build-background.sh to regenerate. |
@@ -9144,23 +9144,6 @@ const Migration = (() => { |
9144 | 9144 | }); |
9145 | 9145 | } |
9146 | 9146 |
|
9147 | | - // 7. Create initial performance snapshot |
9148 | | - try { |
9149 | | - const perfHistory = await chrome.storage.local.get('perfHistory'); |
9150 | | - if (!perfHistory.perfHistory || perfHistory.perfHistory.length === 0) { |
9151 | | - const allScripts = Object.values(scripts); |
9152 | | - const snapshot = {}; |
9153 | | - for (const s of allScripts) { |
9154 | | - if (s.stats) { |
9155 | | - snapshot[s.id] = { avgTime: s.stats.avgTime || 0, runs: s.stats.runs || 0, errors: s.stats.errors || 0 }; |
9156 | | - } |
9157 | | - } |
9158 | | - await chrome.storage.local.set({ |
9159 | | - perfHistory: [{ timestamp: Date.now(), data: snapshot }] |
9160 | | - }); |
9161 | | - } |
9162 | | - } catch {} |
9163 | | - |
9164 | 9147 | console.log('[Migration] v2.0 migration complete'); |
9165 | 9148 | } |
9166 | 9149 |
|
@@ -9284,34 +9267,7 @@ const QuotaManager = (() => { |
9284 | 9267 | } |
9285 | 9268 | } |
9286 | 9269 |
|
9287 | | - // 2. Trim analytics data to 30 days (from 90) |
9288 | | - if (options.analytics !== false) { |
9289 | | - const analyticsData = await chrome.storage.local.get('analytics'); |
9290 | | - if (analyticsData.analytics) { |
9291 | | - const cutoff = new Date(Date.now() - 30 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); |
9292 | | - const old = Object.keys(analyticsData.analytics).filter(d => d < cutoff); |
9293 | | - if (old.length > 0) { |
9294 | | - for (const date of old) delete analyticsData.analytics[date]; |
9295 | | - await chrome.storage.local.set({ analytics: analyticsData.analytics }); |
9296 | | - actions.push(`Pruned ${old.length} days of old analytics`); |
9297 | | - freedBytes += old.length * 500; // Estimate |
9298 | | - } |
9299 | | - } |
9300 | | - } |
9301 | | - |
9302 | | - // 3. Trim performance history to 14 days |
9303 | | - if (options.perfHistory !== false) { |
9304 | | - const perfData = await chrome.storage.local.get('perfHistory'); |
9305 | | - if (perfData.perfHistory && perfData.perfHistory.length > 14) { |
9306 | | - const trimmed = perfData.perfHistory.slice(-14); |
9307 | | - const removed = perfData.perfHistory.length - trimmed.length; |
9308 | | - await chrome.storage.local.set({ perfHistory: trimmed }); |
9309 | | - actions.push(`Pruned ${removed} perf history entries`); |
9310 | | - freedBytes += removed * 200; |
9311 | | - } |
9312 | | - } |
9313 | | - |
9314 | | - // 4. Trim error log to 200 entries |
| 9270 | + // 2. Trim error log to 200 entries |
9315 | 9271 | if (options.errorLog !== false) { |
9316 | 9272 | const errData = await chrome.storage.local.get('errorLog'); |
9317 | 9273 | if (errData.errorLog && errData.errorLog.length > 200) { |
@@ -11471,42 +11427,6 @@ async function handleMessage(message, sender) { |
11471 | 11427 | } |
11472 | 11428 |
|
11473 | 11429 | // v2.0: Script Analytics |
11474 | | - case 'recordAnalytics': { |
11475 | | - const analyticsData = await chrome.storage.local.get('analytics'); |
11476 | | - const analytics = analyticsData.analytics || {}; |
11477 | | - const today = new Date().toISOString().slice(0, 10); |
11478 | | - if (!analytics[today]) analytics[today] = {}; |
11479 | | - const sid = data.scriptId; |
11480 | | - if (!analytics[today][sid]) analytics[today][sid] = { runs: 0, totalTime: 0, errors: 0, urls: [] }; |
11481 | | - analytics[today][sid].runs++; |
11482 | | - analytics[today][sid].totalTime += data.duration || 0; |
11483 | | - if (data.error) analytics[today][sid].errors++; |
11484 | | - if (data.url && !analytics[today][sid].urls.includes(data.url)) { |
11485 | | - analytics[today][sid].urls.push(data.url); |
11486 | | - if (analytics[today][sid].urls.length > 50) analytics[today][sid].urls = analytics[today][sid].urls.slice(-50); |
11487 | | - } |
11488 | | - // Prune data older than 90 days |
11489 | | - const cutoffDate = new Date(Date.now() - 90 * 24 * 60 * 60 * 1000).toISOString().slice(0, 10); |
11490 | | - for (const date of Object.keys(analytics)) { |
11491 | | - if (date < cutoffDate) delete analytics[date]; |
11492 | | - } |
11493 | | - await chrome.storage.local.set({ analytics }); |
11494 | | - return { success: true }; |
11495 | | - } |
11496 | | - case 'getAnalytics': { |
11497 | | - const aData = await chrome.storage.local.get('analytics'); |
11498 | | - return { analytics: aData.analytics || {} }; |
11499 | | - } |
11500 | | - case 'getAnalyticsForScript': { |
11501 | | - const aData2 = await chrome.storage.local.get('analytics'); |
11502 | | - const analytics2 = aData2.analytics || {}; |
11503 | | - const scriptData = {}; |
11504 | | - for (const [date, scripts] of Object.entries(analytics2)) { |
11505 | | - if (scripts[data.scriptId]) scriptData[date] = scripts[data.scriptId]; |
11506 | | - } |
11507 | | - return { data: scriptData }; |
11508 | | - } |
11509 | | - |
11510 | 11430 | // v2.0: Profiles |
11511 | 11431 | case 'getProfiles': { |
11512 | 11432 | const pData = await chrome.storage.local.get(['profiles', 'activeProfileId']); |
@@ -12703,22 +12623,6 @@ async function handleMessage(message, sender) { |
12703 | 12623 | } |
12704 | 12624 |
|
12705 | 12625 | // Performance History |
12706 | | - case 'getPerfHistory': { |
12707 | | - const histData = await chrome.storage.local.get('perfHistory'); |
12708 | | - return { history: histData.perfHistory || [] }; |
12709 | | - } |
12710 | | - |
12711 | | - case 'savePerfSnapshot': { |
12712 | | - const histData2 = await chrome.storage.local.get('perfHistory'); |
12713 | | - const history = histData2.perfHistory || []; |
12714 | | - history.push({ timestamp: Date.now(), data: data.snapshot }); |
12715 | | - // Keep last 30 days |
12716 | | - const cutoff = Date.now() - (30 * 24 * 60 * 60 * 1000); |
12717 | | - const trimmed = history.filter(h => h.timestamp > cutoff); |
12718 | | - await chrome.storage.local.set({ perfHistory: trimmed }); |
12719 | | - return { success: true }; |
12720 | | - } |
12721 | | - |
12722 | 12626 | // Easy Cloud Sync |
12723 | 12627 | case 'easyCloudConnect': { |
12724 | 12628 | if (typeof EasyCloudSync !== 'undefined') { |
|
0 commit comments