Skip to content

Commit

Permalink
fix: default theme on select
Browse files Browse the repository at this point in the history
  • Loading branch information
misa198 committed Apr 5, 2022
1 parent 2243c26 commit 682c9ff
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
38 changes: 19 additions & 19 deletions src/scripts/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,27 +179,27 @@ const init = async () => {

// ============ Code color theme ===================

const applyColorTheme = async () => {
const changeTheme = (themeName?: string) => {
const body = document.querySelector('body') as HTMLElement;
const { classList } = body;
const currentThemeClass = Array.from(classList).find((className) =>
className.startsWith(`${colorThemeDeaultClass}`)
const changeTheme = (themeName?: string) => {
const body = document.querySelector('body') as HTMLElement;
const { classList } = body;
const currentThemeClass = Array.from(classList).find((className) =>
className.startsWith(`${colorThemeDeaultClass}`)
);
if (currentThemeClass) {
body.classList.remove(currentThemeClass);
}
if (themeName) {
const foundTheme = colorThemes.find(
(colorTheme) => colorTheme === themeName
);
if (currentThemeClass) {
body.classList.remove(currentThemeClass);
}
if (themeName) {
const foundTheme = colorThemes.find(
(colorTheme) => colorTheme === themeName
);
if (foundTheme) {
classList.add(`${colorThemeDeaultClass}-${foundTheme}`);
set({ [KEYS.MISA198_CODE_COLOR_THEME]: foundTheme });
}
}
};
if (foundTheme) {
classList.add(`${colorThemeDeaultClass}-${foundTheme}`);
set({ [KEYS.MISA198_CODE_COLOR_THEME]: foundTheme });
} else set({ [KEYS.MISA198_CODE_COLOR_THEME]: 'default' });
}
};

const applyColorTheme = async () => {
observe('body', {
add() {
get([KEYS.MISA198_CODE_COLOR_THEME], (result) => {
Expand Down
2 changes: 1 addition & 1 deletion src/scripts/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ get([KEYS.MISA198_CODE_COLOR_THEME], (result) => {
);
if (foundTheme) {
select.value = foundTheme;
}
} else select.value = 'default';
}
});

Expand Down

0 comments on commit 682c9ff

Please sign in to comment.