refactor: decompose CSS, unify dark mode, extract shared modules

Structural cleanup based on thermo-nuclear code quality review:
- Extract shared color-picker.css and color-popover.css from badges.css (611→85 lines)
- Extract shared lib/presets.js for preset CRUD used by popup and popover
- Unify dark mode to single applyDarkModeClass on <html>, removing 4 scattered functions
- Fix stale closure in startPostObserver, data-driven reload key check
- Remove dead exports, getHelpers wrapper, duplicated colorToHex
- Replace DOM expando properties with state array in popup.js

Net: -318 lines of duplication, no file over 401 lines.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
2026-08-28 01:39:25 -04:00
parent 80689c6f8d
commit 00507fe87c
15 changed files with 826 additions and 1012 deletions

View File

@@ -6,12 +6,6 @@
function applyColorsToContainer(container, settings, subredditName) {
const prefix = window.RedditTweaks.getColorPrefix(settings);
if (window.RedditTweaks.isDarkMode(settings)) {
container.classList.add("rt-dark");
} else {
container.classList.remove("rt-dark");
}
const entry = subredditName && settings.subredditColors[subredditName];
const overrides = entry && entry[prefix];
@@ -98,10 +92,6 @@
const subredditName = container.getAttribute("data-rt-subreddit");
applyColorsToContainer(container, settings, subredditName);
});
if (window.RedditTweaks.colorPopover && window.RedditTweaks.colorPopover.refreshTheme) {
window.RedditTweaks.colorPopover.refreshTheme(settings);
}
}
function apply(settings) {
@@ -113,8 +103,6 @@
window.RedditTweaks.badgeTweak = {
apply: apply,
updateColors: updateColors,
isDarkMode: window.RedditTweaks.isDarkMode,
getColorPrefix: window.RedditTweaks.getColorPrefix,
processNewPosts: processPosts,
};
})();