feat: mode-aware subreddit color overrides with v1→v2 migration

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-26 16:00:52 -04:00
parent 6bf79351a7
commit af7afde592
2 changed files with 26 additions and 6 deletions

View File

@@ -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;
}