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

@@ -5,6 +5,7 @@
var observer = new MutationObserver(function () {
window.RedditTweaks.loadSettings().then(function (updated) {
if (updated.darkMode === "auto") {
window.RedditTweaks.applyDarkModeClass(updated);
if (updated.badgeLayout) {
window.RedditTweaks.badgeTweak.updateColors(updated);
}
@@ -44,10 +45,10 @@
}
if (hasNewPosts) {
window.RedditTweaks.loadSettings().then(function (updated) {
if (settings.badgeLayout) {
if (updated.badgeLayout) {
window.RedditTweaks.badgeTweak.processNewPosts(updated);
}
if (settings.cardLayout) {
if (updated.cardLayout) {
window.RedditTweaks.cardTweak.processNewPosts(updated);
}
});
@@ -62,6 +63,8 @@
var settings = await window.RedditTweaks.loadSettings();
if (!settings.enabled) return;
window.RedditTweaks.applyDarkModeClass(settings);
if (settings.badgeLayout) {
document.documentElement.classList.add("rt-badges-enabled");
window.RedditTweaks.badgeTweak.apply(settings);
@@ -80,18 +83,19 @@
startDarkModeObserver(settings);
}
var RELOAD_KEYS = ["enabled", "badgeLayout", "fontOverride", "cardLayout"];
browser.storage.onChanged.addListener(function (changes) {
if (
(changes.enabled && changes.enabled.newValue !== changes.enabled.oldValue) ||
(changes.badgeLayout && changes.badgeLayout.newValue !== changes.badgeLayout.oldValue) ||
(changes.fontOverride && changes.fontOverride.newValue !== changes.fontOverride.oldValue) ||
(changes.cardLayout && changes.cardLayout.newValue !== changes.cardLayout.oldValue)
) {
var needsReload = RELOAD_KEYS.some(function (key) {
return changes[key] && changes[key].newValue !== changes[key].oldValue;
});
if (needsReload) {
location.reload();
return;
}
window.RedditTweaks.loadSettings().then(function (updated) {
window.RedditTweaks.applyDarkModeClass(updated);
if (updated.badgeLayout) {
window.RedditTweaks.badgeTweak.updateColors(updated);
}