fixed theme indicator not working with randomised themes

This commit is contained in:
Jack 2020-09-08 00:32:08 +01:00
parent a1f6cb73bd
commit 487ebfbb8a
2 changed files with 14 additions and 4 deletions

View file

@ -285,13 +285,18 @@ function refreshThemeButtons() {
).empty();
let themesEl = $(".pageSettings .section.themes .allThemes.buttons").empty();
let activeThemeName = config.theme;
if (config.randomTheme !== "off" && randomTheme !== null) {
activeThemeName = randomTheme;
}
getSortedThemesList().then((themes) => {
//first show favourites
if (config.favThemes.length > 0) {
favThemesEl.css({ paddingBottom: "1rem" });
themes.forEach((theme) => {
if (config.favThemes.includes(theme.name)) {
let activeTheme = config.theme === theme.name ? "active" : "";
let activeTheme = activeThemeName === theme.name ? "active" : "";
favThemesEl.append(
`<div class="theme button" theme='${theme.name}' style="color:${
theme.textColor
@ -308,7 +313,7 @@ function refreshThemeButtons() {
//then the rest
themes.forEach((theme) => {
if (!config.favThemes.includes(theme.name)) {
let activeTheme = config.theme === theme.name ? "active" : "";
let activeTheme = activeThemeName === theme.name ? "active" : "";
themesEl.append(
`<div class="theme button" theme='${theme.name}' style="color:${
theme.textColor
@ -333,6 +338,7 @@ function updateSettingsPage() {
setActiveThemeTab();
setCustomThemeInputs();
updateDiscordSettingsSection();
refreshThemeButtons();
}
function showCustomThemeShare() {

View file

@ -708,20 +708,24 @@ function setTheme(name, nosave) {
if (!nosave) saveConfigToCookie();
}
let randomTheme = null;
function randomiseTheme() {
var randomList = themesList.map((t) => {
return t.name;
});
if (config.randomTheme === "fav" && config.favThemes.length > 0)
randomList = config.favThemes;
let randomtheme = randomList[Math.floor(Math.random() * randomList.length)];
setTheme(randomtheme, true);
randomTheme = randomList[Math.floor(Math.random() * randomList.length)];
setTheme(randomTheme, true);
}
function setRandomTheme(val, nosave) {
if (val === undefined || val === true || val === false) {
val = "off";
}
if (val === "off") {
randomTheme = null;
}
config.randomTheme = val;
if (!nosave) saveConfigToCookie();
}