forked from GreenAsh/code-highlighter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.js
65 lines (65 loc) · 2.18 KB
/
settings.js
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
const code = {
highlighter: {
settings: {
_langKey_fallback_1: 'code.highlighter.lang',
_langKey: 'ch_lang',
_themeKey: 'ch_theme',
_defaultLang: 'json',
languages:{
'php': 1,
'go': 1,
'python': 1,
'java': 1,
'kotlin': 1,
'swift': 1,
'js': 1,
'ts': 1,
'jsx': 1,
'html': 1,
'css': 1,
'json': 1,
'http': 1,
'bash': 1
},
themes: {
'Default (PrismJS)': 'default',
'Meterial Light': 'material-light',
'Light Transparent (idea)': 'idea',
'VS Theme': 'vs',
'Okaidia': 'okaidia',
'Tomorrow Night': 'tomorrow-night'
},
getLang: function() {
const lang = this._getLang(this._langKey, this._getLang(this._langKey_fallback_1, this._defaultLang));
if (lang !== this._defaultLang){
this.setLang(lang); // overwrite fallback
}
return lang;
},
_getLang(propertyKey, defaultValue){
const value = localStorage.getItem(propertyKey);
if (this.languages[value] === 1){
return value;
} else {
return defaultValue;
}
},
setLang: function(value) {
if (this.languages[value] === 1){
localStorage.setItem(this._langKey, value);
localStorage.removeItem(this._langKey_fallback_1); // overwrite fallback key
}
},
isLangStored(){
const lang = localStorage.getItem(this._langKey);
return this.languages[lang] === 1;
},
getTheme() {
return localStorage.getItem(this._themeKey);
},
setTheme(theme) {
localStorage.setItem(this._themeKey, theme);
}
}
}
};