feat: mode-aware subreddit color overrides with v1→v2 migration
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -19,10 +19,29 @@
|
||||
subredditColors: {},
|
||||
};
|
||||
|
||||
function migrateSubredditColors(colors) {
|
||||
let migrated = false;
|
||||
const result = {};
|
||||
for (const name of Object.keys(colors)) {
|
||||
const entry = colors[name];
|
||||
if (entry && entry.bg !== undefined && !entry.light && !entry.dark) {
|
||||
result[name] = { light: { bg: entry.bg, border: entry.border, text: entry.text }, dark: { bg: entry.bg, border: entry.border, text: entry.text } };
|
||||
migrated = true;
|
||||
} else {
|
||||
result[name] = entry;
|
||||
}
|
||||
}
|
||||
return { result: result, migrated: migrated };
|
||||
}
|
||||
|
||||
async function loadSettings() {
|
||||
const stored = await browser.storage.local.get(null);
|
||||
const merged = Object.assign({}, DEFAULTS, stored);
|
||||
merged.subredditColors = Object.assign({}, merged.subredditColors);
|
||||
const migration = migrateSubredditColors(merged.subredditColors || {});
|
||||
merged.subredditColors = migration.result;
|
||||
if (migration.migrated) {
|
||||
await browser.storage.local.set({ subredditColors: merged.subredditColors });
|
||||
}
|
||||
return merged;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user