-
Notifications
You must be signed in to change notification settings - Fork 100
Expand file tree
/
Copy pathsettings.module.js
More file actions
183 lines (168 loc) · 5.14 KB
/
settings.module.js
File metadata and controls
183 lines (168 loc) · 5.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/* eslint-disable no-shadow */
import Vue from "vue";
import { createSimpleMutation, getUILang, getLang } from "@/utils/functions";
const userLanguage = navigator.language || navigator.userLanguage || "en";
const englishNamePrefs = new Set(["en", "es", "fr", "id", "pt", "de", "ru", "it"]);
const lang = getLang(userLanguage);
const initialState = {
// Language
lang: getUILang(userLanguage), // UI lang
foolsLang: "",
clipLangs: [lang],
// Site
darkMode: true,
defaultOpen: "home",
// Content
redirectMode: false,
autoplayVideo: false,
scrollMode: true,
hideThumbnail: false,
hidePlaceholder: false,
hideMissing: false,
nameProperty: englishNamePrefs.has(lang) ? "english_name" : "name",
hideCollabStreams: false,
hiddenGroups: {},
ignoredTopics: [],
// Valid values: "grid" | "list" | "denseList"
homeViewMode: "grid",
YTEmbedVariant: "youtube",
// Live TL Window Settings
liveTlStickBottom: false,
liveTlLang: lang,
liveTlFontSize: 14,
liveTlShowVerified: true, // show verified messages
liveTlShowModerator: true, // show moderator messages
liveTlShowVtuber: true, // show vtuber messages
liveTlShowLocalTime: false, // show client local time
liveTlWindowSize: 0, // Default size, otherwise percentage height
liveTlShowSubtitle: true, // Show subtitles on videos
liveTlHideSpoiler: false, // Hide message past current video time
liveTlBlocked: [],
blockedChannels: [],
// Deprecated
canUseWebP: true,
testedWebP: false,
};
export const state = { ...initialState };
const getters = {
useEnName(state) {
return state.nameProperty === "english_name";
},
blockedChannelIDs(state) {
return new Set(state.blockedChannels.map((x) => x.id));
},
liveTlBlockedNames(state) {
return new Set(state.liveTlBlocked);
},
ignoredTopics(state) {
return new Set(state.ignoredTopics);
},
};
const actions = {};
const mutations = {
setDarkMode(state, val) {
state.darkMode = val;
localStorage.setItem("darkMode", val ? "true" : "false");
},
setRedirectMode(state, val) {
state.redirectMode = val;
},
setAutoplayVideo(state, val) {
state.autoplayVideo = val;
},
noWebPSupport(state) {
state.canUseWebP = false;
},
testedWebP(state) {
state.testedWebP = true;
},
setUseEnName(state, payload) {
state.nameProperty = payload ? "english_name" : "name";
},
setHideThumbnail(state, val) {
state.hideThumbnail = val;
},
setLanguage(state, val) {
state.lang = val;
},
setClipLangs(state, val) {
state.clipLangs = val;
},
setIgnoredTopics(state, val) {
state.ignoredTopics = val;
},
setScrollMode(state, val) {
state.scrollMode = val;
},
setYTEmbedVariant(state, val) {
state.YTEmbedVariant = val;
},
...createSimpleMutation([
"defaultOpen",
"liveTlStickBottom",
"liveTlLang",
"liveTlFontSize",
"liveTlShowVerified",
"liveTlShowModerator",
"liveTlShowLocalTime",
"liveTlWindowSize",
"hideCollabStreams",
"ignoredTopics",
"liveTlShowVtuber",
"liveTlShowSubtitle",
"liveTlHideSpoiler",
"hidePlaceholder",
"hideMissing",
"homeViewMode",
"YTEmbedVariant",
]),
resetState(state) {
Object.assign(state, initialState);
localStorage.removeItem("theme");
localStorage.removeItem("darkMode");
},
toggleBlocked(state, channel) {
// initialize if doesn't exist
if (!state.blockedChannels) Vue.set(state, "blockedChannels", []);
// determine to add or subtract:
if (state.blockedChannels.filter((x) => x.id === channel.id).length > 0) {
Vue.delete(
state.blockedChannels,
state.blockedChannels.findIndex((x) => x.id === channel.id),
);
} else {
state.blockedChannels.push(channel);
}
},
toggleGroupDisplay(state, group) {
const groupName = `${group.title}`.toLowerCase();
const orgName = `${group.org}`;
if (!state.hiddenGroups) Vue.set(state, "hiddenGroups", {});
if (!state.hiddenGroups[orgName]) Vue.set(state.hiddenGroups, `${orgName}`, []);
// determine to add or subtract:
if (state.hiddenGroups[orgName].includes(groupName)) {
Vue.delete(
state.hiddenGroups[orgName],
state.hiddenGroups[orgName].findIndex((x) => x.toLowerCase() === groupName),
);
} else {
state.hiddenGroups[orgName].push(groupName);
}
},
toggleLiveTlBlocked(state, name) {
if (!state.liveTlBlocked) Vue.set(state, "blockedChannels", []);
const index = state.liveTlBlocked.indexOf(name);
if (index !== -1) {
Vue.delete(state.liveTlBlocked, index);
} else {
state.liveTlBlocked.push(name);
}
},
};
export default {
namespaced: true,
state,
getters,
actions,
mutations,
};