Skip to content

Commit

Permalink
Add option to disable alternate colors in chat
Browse files Browse the repository at this point in the history
  • Loading branch information
stevencrader committed Aug 18, 2024
1 parent 6a0a5ff commit 4c816d7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
24 changes: 16 additions & 8 deletions src/components/open-chat/open-chat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,16 @@
&.chat-history--subscribed {
background-image: linear-gradient(to right, var(--light-subscribed), var(--light-accent));
}
}

&:nth-child(odd) {
background-color: var(--light-accent2);
&.alternate-colors {
.chat-history--row {
&:nth-child(odd) {
background-color: var(--light-accent2);

&.chat-history--subscribed {
background-image: linear-gradient(to right, var(--light-subscribed), var(--light-accent2));
&.chat-history--subscribed {
background-image: linear-gradient(to right, var(--light-subscribed), var(--light-accent2));
}
}
}
}
Expand All @@ -72,12 +76,16 @@
&.chat-history--subscribed {
background-image: linear-gradient(to right, var(--dark-subscribed), var(--dark-accent));
}
}

&:nth-child(odd) {
background-color: var(--dark-accent2);
&.alternate-colors {
.chat-history--row {
&:nth-child(odd) {
background-color: var(--dark-accent2);

&.chat-history--subscribed {
background-image: linear-gradient(to right, var(--dark-subscribed), var(--dark-accent2));
&.chat-history--subscribed {
background-image: linear-gradient(to right, var(--dark-subscribed), var(--dark-accent2));
}
}
}
}
Expand Down
5 changes: 4 additions & 1 deletion src/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { replacePageContent } from "./rantstatspage"
import {
registerRumbleThemeObserver,
registerSystemColorSchemeWatcher,
updateAlternateColorsStyle,
updateChatThemeStyle,
updateThemeStyle,
} from "./theme"
Expand All @@ -32,7 +33,9 @@ registerSystemColorSchemeWatcher()
registerRumbleThemeObserver()
updateChatThemeStyle()

getOptions().then()
getOptions().then((options: Options) => {
updateAlternateColorsStyle(options?.alternateColors)
})

// run clean history at the beginning of each load
cleanHistory().then()
Expand Down
5 changes: 4 additions & 1 deletion src/message-options.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { setLastSortOrder, sortChats } from "./components/rants/rant"
import { updateThemeStyle } from "./theme"
import { updateAlternateColorsStyle, updateThemeStyle } from "./theme"
import { Messages } from "./types/messages"
import { Options, SortOrder, Theme } from "./types/option-types"

Expand All @@ -18,4 +18,7 @@ export const handleUpdateOptions = (options: Options): void => {
if (options?.theme !== undefined) {
updateThemeStyle(options.theme as Theme)
}
if (options?.alternateColors !== undefined) {
updateAlternateColorsStyle(options.alternateColors)
}
}
11 changes: 11 additions & 0 deletions src/pages/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,17 @@ <h1>RantStats Extension Options</h1>
</div>
</div>

<div class="option">
<div class="option-info">
<label class="name" for="alternate-colors" title="Alternate colors">Alternate colors</label>
<p class="description">Alternate colors of messages in chat</p>
</div>

<div class="selector">
<input type="checkbox" id="alternate-colors" />
</div>
</div>

<div class="option">
<div class="option-info">
<label
Expand Down
3 changes: 3 additions & 0 deletions src/pages/options/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const historyInput = document.getElementById("history") as HTMLInputElement
const themeSelect = document.getElementById("theme") as HTMLSelectElement
const openLocationCheckbox = document.getElementById("open-location") as HTMLInputElement
const bytesUseSpan = document.getElementById(CONSTS.BYTES_USE_ID) as HTMLSpanElement
const alternateColorsCheckbox = document.getElementById("alternate-colors") as HTMLInputElement

/**
* Toggle showing or hiding the sub-options section based on the check state
Expand Down Expand Up @@ -44,6 +45,7 @@ const setOptions = (options: Options): void => {
historyInput.value = options.historyDays.toString()
themeSelect.value = options.theme.toString()
openLocationCheckbox.checked = options.asPopup
alternateColorsCheckbox.checked = options.alternateColors

updateUsage()
}
Expand All @@ -64,6 +66,7 @@ const saveOptions = (): void => {
historyDays: parseInt(historyInput.value, 10),
theme: themeSelect.value,
asPopup: openLocationCheckbox.checked,
alternateColors: alternateColorsCheckbox.checked,
}

updateOptions(currentOptions).then(() => {
Expand Down
17 changes: 16 additions & 1 deletion src/theme.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getTheme } from "./cache"
import { getChatButtons } from "./components/open-chat/chat-buttons"
import { rumbleThemeChanged } from "./components/events/event-rumble-theme-changed"
import { getChatButtons } from "./components/open-chat/chat-buttons"
import { CONSTS } from "./types/consts"
import { Theme } from "./types/option-types"

Expand Down Expand Up @@ -77,6 +77,21 @@ export const updateThemeStyle = (themePreference: Theme): void => {
}
}

/**
* Update the chat to show or not show alternating colors
* @param alternate should colors alternate or not
*/
export const updateAlternateColorsStyle = (alternate: boolean): void => {
const chatList = document.getElementById("chat-history-list") as HTMLUListElement
if (chatList) {
if (alternate) {
chatList.classList.add("alternate-colors")
} else {
chatList.classList.remove("alternate-colors")
}
}
}

/**
* Register watcher of the operating system color scheme.
*
Expand Down
5 changes: 5 additions & 0 deletions src/types/option-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ export type Options = {
* Open Rants in popup instead of sidebar
*/
asPopup: boolean
/**
* Alternate colors of messages in chat
*/
alternateColors: boolean
}

/**
Expand All @@ -74,4 +78,5 @@ export const defaultOptions: Options = {
historyDays: 30,
theme: Theme.Rumble.toString(),
asPopup: false,
alternateColors: true,
}

0 comments on commit 4c816d7

Please sign in to comment.