mirror of
https://codeberg.org/SafeTwitch/safetwitch.git
synced 2024-12-22 05:12:57 -05:00
Add comments and stuff
This commit is contained in:
parent
7d361da167
commit
d7d4132b9b
1 changed files with 28 additions and 15 deletions
|
@ -1,13 +1,6 @@
|
|||
const locales = ['en-US', 'es-ES', 'nl-NL', 'pt-PT', 'fa-IR', 'he-IL', 'ru-RU', 'ko-KR', 'cs-CZ', 'pl-PL', 'it-IT', 'fr-FR', 'uk-UA', 'de-DE']
|
||||
const languages = ['English', 'Español', 'Nederlands', 'Português', 'فارسی', 'עִבְרִית', 'Русский', '한국어', 'Česky', 'Polski', 'Italia', 'Français', 'Українська', 'Deutsch']
|
||||
|
||||
export const setLanguage = (selectedLanguage: string, i18n: any) => {
|
||||
// Locales and languages in arrays to match them
|
||||
const locale = locales[languages.indexOf(selectedLanguage)]
|
||||
localStorage.setItem("language", locale)
|
||||
i18n.locale = locale
|
||||
}
|
||||
|
||||
export interface SettingsCheckbox {
|
||||
name: string
|
||||
selected: boolean,
|
||||
|
@ -34,7 +27,22 @@ export interface Settings {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the language by locale
|
||||
* @param selectedLanguage language to set
|
||||
* @param i18n the i18n class in use
|
||||
*/
|
||||
export const setLanguage = (selectedLanguage: string, i18n: any) => {
|
||||
// Locales and languages in arrays to match them
|
||||
const locale = locales[languages.indexOf(selectedLanguage)]
|
||||
localStorage.setItem("language", locale)
|
||||
i18n.locale = locale
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the default settings
|
||||
* @returns Settings
|
||||
*/
|
||||
export function getDefaultSettings(): Settings {
|
||||
return {
|
||||
version: import.meta.env.SAFETWITCH_TAG,
|
||||
|
@ -131,6 +139,13 @@ export function syncUserSettings(settings: Settings): {settings: Settings, chang
|
|||
return { settings: synced, changed: true }
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a users' setting's value from the setting's key
|
||||
* @param key Setting key to get
|
||||
* @returns a boolean or string depending on setting type
|
||||
* @example
|
||||
* getSetting("audioOnly") // false
|
||||
*/
|
||||
export function getSetting(key: string): boolean | string {
|
||||
const storage = localStorage.getItem('settings')
|
||||
let parsed
|
||||
|
@ -143,18 +158,16 @@ export function getSetting(key: string): boolean | string {
|
|||
return parsed[key].selected
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current theme
|
||||
* @returns the name of the current theme
|
||||
* @default string light
|
||||
*/
|
||||
export function getTheme() {
|
||||
return localStorage.getItem('theme') || "light"
|
||||
}
|
||||
|
||||
export function chatVisible() {
|
||||
const p = getSetting('chatVisible')
|
||||
// Flip becuase on the setting page it's
|
||||
// displayed as "Hide Chat", but the value
|
||||
// is chatVisible
|
||||
return !p
|
||||
}
|
||||
|
||||
// every avaliable theme
|
||||
export const themeList = [
|
||||
{
|
||||
// name your theme anything that could be a valid css class name
|
||||
|
|
Loading…
Reference in a new issue