2026-08-26 15:02:46 -04:00
|
|
|
|
(function () {
|
|
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
|
|
const COLOR_KEYS = [
|
2026-08-26 15:32:33 -04:00
|
|
|
|
"light.subredditBgColor",
|
2026-08-26 15:02:46 -04:00
|
|
|
|
"light.subredditBorderColor",
|
|
|
|
|
|
"light.subredditTextColor",
|
|
|
|
|
|
"light.commentsBgColor",
|
|
|
|
|
|
"light.commentsBorderColor",
|
|
|
|
|
|
"light.commentsTextColor",
|
2026-08-26 15:32:33 -04:00
|
|
|
|
"dark.subredditBgColor",
|
2026-08-26 15:02:46 -04:00
|
|
|
|
"dark.subredditBorderColor",
|
|
|
|
|
|
"dark.subredditTextColor",
|
|
|
|
|
|
"dark.commentsBgColor",
|
|
|
|
|
|
"dark.commentsBorderColor",
|
|
|
|
|
|
"dark.commentsTextColor",
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
|
|
function colorToHex(val) {
|
2026-08-26 15:32:33 -04:00
|
|
|
|
if (!val) return "#ffffff";
|
2026-08-26 15:02:46 -04:00
|
|
|
|
return val;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function populateControls(settings) {
|
|
|
|
|
|
document.getElementById("enabled").checked = settings.enabled;
|
|
|
|
|
|
document.getElementById("darkMode").value = settings.darkMode;
|
|
|
|
|
|
|
|
|
|
|
|
COLOR_KEYS.forEach(function (key) {
|
|
|
|
|
|
const el = document.getElementById(key);
|
|
|
|
|
|
if (el) el.value = colorToHex(settings[key]);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
renderSubredditOverrides(settings.subredditColors || {});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function renderSubredditOverrides(overrides) {
|
|
|
|
|
|
const list = document.getElementById("subredditList");
|
|
|
|
|
|
list.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
|
|
Object.entries(overrides).forEach(function ([name, colors]) {
|
|
|
|
|
|
addSubredditEntry(name, colors);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function addSubredditEntry(name, colors) {
|
|
|
|
|
|
const list = document.getElementById("subredditList");
|
|
|
|
|
|
const entry = document.createElement("div");
|
|
|
|
|
|
entry.className = "subreddit-entry";
|
|
|
|
|
|
|
|
|
|
|
|
const nameInput = document.createElement("input");
|
|
|
|
|
|
nameInput.type = "text";
|
|
|
|
|
|
nameInput.placeholder = "subreddit";
|
|
|
|
|
|
nameInput.value = name || "";
|
|
|
|
|
|
|
|
|
|
|
|
const bgInput = document.createElement("input");
|
|
|
|
|
|
bgInput.type = "color";
|
|
|
|
|
|
bgInput.value = colorToHex(colors?.bg);
|
|
|
|
|
|
bgInput.title = "Background";
|
|
|
|
|
|
|
|
|
|
|
|
const borderInput = document.createElement("input");
|
|
|
|
|
|
borderInput.type = "color";
|
|
|
|
|
|
borderInput.value = colorToHex(colors?.border);
|
|
|
|
|
|
borderInput.title = "Border";
|
|
|
|
|
|
|
|
|
|
|
|
const textInput = document.createElement("input");
|
|
|
|
|
|
textInput.type = "color";
|
|
|
|
|
|
textInput.value = colorToHex(colors?.text);
|
|
|
|
|
|
textInput.title = "Text";
|
|
|
|
|
|
|
|
|
|
|
|
const removeBtn = document.createElement("button");
|
|
|
|
|
|
removeBtn.className = "btn-remove";
|
|
|
|
|
|
removeBtn.textContent = "×";
|
|
|
|
|
|
removeBtn.addEventListener("click", function () {
|
|
|
|
|
|
entry.remove();
|
|
|
|
|
|
saveFromControls();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
[nameInput, bgInput, borderInput, textInput].forEach(function (input) {
|
|
|
|
|
|
input.addEventListener("change", saveFromControls);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
entry.appendChild(nameInput);
|
|
|
|
|
|
entry.appendChild(bgInput);
|
|
|
|
|
|
entry.appendChild(borderInput);
|
|
|
|
|
|
entry.appendChild(textInput);
|
|
|
|
|
|
entry.appendChild(removeBtn);
|
|
|
|
|
|
list.appendChild(entry);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function collectSubredditOverrides() {
|
|
|
|
|
|
const overrides = {};
|
|
|
|
|
|
const entries = document.querySelectorAll(".subreddit-entry");
|
|
|
|
|
|
entries.forEach(function (entry) {
|
|
|
|
|
|
const inputs = entry.querySelectorAll("input");
|
|
|
|
|
|
const name = inputs[0].value.trim().replace(/^r\//, "");
|
|
|
|
|
|
if (name) {
|
|
|
|
|
|
overrides[name] = {
|
|
|
|
|
|
bg: inputs[1].value,
|
|
|
|
|
|
border: inputs[2].value,
|
|
|
|
|
|
text: inputs[3].value,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
return overrides;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-08-26 15:05:48 -04:00
|
|
|
|
async function saveFromControls() {
|
2026-08-26 15:02:46 -04:00
|
|
|
|
const settings = {
|
|
|
|
|
|
enabled: document.getElementById("enabled").checked,
|
|
|
|
|
|
darkMode: document.getElementById("darkMode").value,
|
|
|
|
|
|
subredditColors: collectSubredditOverrides(),
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
COLOR_KEYS.forEach(function (key) {
|
|
|
|
|
|
const el = document.getElementById(key);
|
|
|
|
|
|
if (el) settings[key] = el.value;
|
|
|
|
|
|
});
|
|
|
|
|
|
|
2026-08-26 15:05:48 -04:00
|
|
|
|
try {
|
|
|
|
|
|
await window.RedditTweaks.saveSettings(settings);
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
console.error("Reddit Tweaks: failed to save settings", err);
|
|
|
|
|
|
}
|
2026-08-26 15:02:46 -04:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function init() {
|
|
|
|
|
|
const settings = await window.RedditTweaks.loadSettings();
|
|
|
|
|
|
populateControls(settings);
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("enabled").addEventListener("change", saveFromControls);
|
|
|
|
|
|
document.getElementById("darkMode").addEventListener("change", saveFromControls);
|
|
|
|
|
|
|
|
|
|
|
|
COLOR_KEYS.forEach(function (key) {
|
|
|
|
|
|
const el = document.getElementById(key);
|
|
|
|
|
|
if (el) el.addEventListener("input", saveFromControls);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("addSubreddit").addEventListener("click", function () {
|
|
|
|
|
|
addSubredditEntry("", {});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("resetLight").addEventListener("click", async function () {
|
|
|
|
|
|
const settings = await window.RedditTweaks.loadSettings();
|
|
|
|
|
|
const DEFAULTS = window.RedditTweaks.DEFAULTS;
|
|
|
|
|
|
Object.keys(DEFAULTS).forEach(function (key) {
|
|
|
|
|
|
if (key.startsWith("light.")) settings[key] = DEFAULTS[key];
|
|
|
|
|
|
});
|
|
|
|
|
|
await window.RedditTweaks.saveSettings(settings);
|
|
|
|
|
|
populateControls(settings);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("resetDark").addEventListener("click", async function () {
|
|
|
|
|
|
const settings = await window.RedditTweaks.loadSettings();
|
|
|
|
|
|
const DEFAULTS = window.RedditTweaks.DEFAULTS;
|
|
|
|
|
|
Object.keys(DEFAULTS).forEach(function (key) {
|
|
|
|
|
|
if (key.startsWith("dark.")) settings[key] = DEFAULTS[key];
|
|
|
|
|
|
});
|
|
|
|
|
|
await window.RedditTweaks.saveSettings(settings);
|
|
|
|
|
|
populateControls(settings);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
document.getElementById("resetAll").addEventListener("click", async function () {
|
|
|
|
|
|
if (confirm("Reset all settings to defaults?")) {
|
|
|
|
|
|
await window.RedditTweaks.resetSettings();
|
|
|
|
|
|
const settings = await window.RedditTweaks.loadSettings();
|
|
|
|
|
|
populateControls(settings);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
init();
|
|
|
|
|
|
})();
|