0
Fork 0
mirror of https://codeberg.org/SafeTwitch/safetwitch.git synced 2024-12-22 13:22:58 -05:00

Add comments and stuff

This commit is contained in:
dragongoose 2023-11-04 19:39:22 -04:00
parent 7d361da167
commit d7d4132b9b
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5

View file

@ -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 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'] 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 { export interface SettingsCheckbox {
name: string name: string
selected: boolean, 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 { export function getDefaultSettings(): Settings {
return { return {
version: import.meta.env.SAFETWITCH_TAG, version: import.meta.env.SAFETWITCH_TAG,
@ -131,6 +139,13 @@ export function syncUserSettings(settings: Settings): {settings: Settings, chang
return { settings: synced, changed: true } 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 { export function getSetting(key: string): boolean | string {
const storage = localStorage.getItem('settings') const storage = localStorage.getItem('settings')
let parsed let parsed
@ -143,18 +158,16 @@ export function getSetting(key: string): boolean | string {
return parsed[key].selected return parsed[key].selected
} }
/**
* Gets the current theme
* @returns the name of the current theme
* @default string light
*/
export function getTheme() { export function getTheme() {
return localStorage.getItem('theme') || "light" return localStorage.getItem('theme') || "light"
} }
export function chatVisible() { // every avaliable theme
const p = getSetting('chatVisible')
// Flip becuase on the setting page it's
// displayed as "Hide Chat", but the value
// is chatVisible
return !p
}
export const themeList = [ export const themeList = [
{ {
// name your theme anything that could be a valid css class name // name your theme anything that could be a valid css class name