safetwitch/src/settingsManager.ts

42 lines
989 B
TypeScript
Raw Normal View History

2023-08-18 14:23:59 -04:00
export function getDefaultSettings() {
return {
version: import.meta.env.SAFETWITCH_TAG,
audioOnly: {
name: 'Audio Only',
selected: false,
type: 'checkbox'
},
defaultQuality: {
name: 'Default Quality',
options: ['160p', '360p', '480p', '720p', '1080p'],
selected: '480p',
type: 'option'
},
chatVisible: {
name: 'Hide Chat',
selected: false,
type: 'checkbox'
}
}
}
export function getSetting(key: string): boolean | string {
const storage = localStorage.getItem('settings')
let parsed
if (!storage) {
parsed = getDefaultSettings()
} else {
parsed = JSON.parse(storage)
}
return parsed[key].selected
}
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
}