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

Add ability to export and import followers with settings #121

This commit is contained in:
dragongoose 2024-06-02 11:01:40 -04:00
parent 7018e264b2
commit e5d021e94a
No known key found for this signature in database
GPG key ID: 01397EEC371CDAA5
3 changed files with 19 additions and 14 deletions

View file

@ -1,4 +1,5 @@
<script lang="ts"> <script lang="ts">
import { getFollows } from '@/settingsManager';
import { ref } from 'vue' import { ref } from 'vue'
export default { export default {
@ -33,13 +34,11 @@ export default {
* @returns true if streamer was followed, false if streamer was already followed. * @returns true if streamer was followed, false if streamer was already followed.
*/ */
followStreamer(username: string): boolean { followStreamer(username: string): boolean {
const follows = localStorage.getItem('following') || '[]' let follows = getFollows()
let parsedFollows: string[] = JSON.parse(follows) if (follows.includes(username)) return false
if (parsedFollows.includes(username)) return false follows.push(username)
localStorage.setItem('following', JSON.stringify(follows))
parsedFollows.push(username)
localStorage.setItem('following', JSON.stringify(parsedFollows))
return true return true
}, },
@ -49,13 +48,12 @@ export default {
* @returns true if unfollowed, false if not followed. * @returns true if unfollowed, false if not followed.
*/ */
unfollowStreamer(username: string): boolean { unfollowStreamer(username: string): boolean {
const follows = localStorage.getItem('following') || '[]' let follows = getFollows()
let parsedFollows: string[] = JSON.parse(follows)
const index = parsedFollows.indexOf(username) const index = follows.indexOf(username)
if (index === -1) return false if (index === -1) return false
parsedFollows.splice(index, 1) follows.splice(index, 1)
localStorage.setItem('following', JSON.stringify(parsedFollows)) localStorage.setItem('following', JSON.stringify(follows))
return true return true
} }

View file

@ -65,6 +65,7 @@ export interface Settings {
streamerAboutSectionVisible: SettingsCheckbox streamerAboutSectionVisible: SettingsCheckbox
autoplay: SettingsCheckbox autoplay: SettingsCheckbox
} }
followers: string[]
} }
/** /**
@ -124,7 +125,8 @@ export function getDefaultSettings(): Settings {
selected: false, selected: false,
type: 'checkbox' type: 'checkbox'
} }
} },
followers: []
} }
} }
@ -163,7 +165,8 @@ export function syncUserSettings(settings: Settings): { settings: Settings; chan
version: defaultSettings.version, version: defaultSettings.version,
settings: { settings: {
...oldSettings ...oldSettings
} },
followers: []
} }
userSettings = migrated userSettings = migrated

View file

@ -5,7 +5,8 @@ import {
syncUserSettings, syncUserSettings,
setLanguage, setLanguage,
themeList, themeList,
getTheme getTheme,
getFollows
} from '@/settingsManager' } from '@/settingsManager'
import type { Settings } from '@/settingsManager' import type { Settings } from '@/settingsManager'
@ -55,6 +56,8 @@ export default {
download() { download() {
var hiddenElement = document.createElement('a') var hiddenElement = document.createElement('a')
this.settings.followers = getFollows()
hiddenElement.href = 'data:attachment/text,' + encodeURI(JSON.stringify(this.settings)) hiddenElement.href = 'data:attachment/text,' + encodeURI(JSON.stringify(this.settings))
hiddenElement.target = '_blank' hiddenElement.target = '_blank'
hiddenElement.download = 'safetwitch_prefs.json' hiddenElement.download = 'safetwitch_prefs.json'
@ -72,6 +75,7 @@ export default {
settings = parsed settings = parsed
} }
localStorage.setItem('following', JSON.stringify(settings.followers))
this.settings = settings this.settings = settings
this.save() this.save()
} }