-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlanguage-settings.js
More file actions
189 lines (169 loc) · 5.17 KB
/
Copy pathlanguage-settings.js
File metadata and controls
189 lines (169 loc) · 5.17 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
184
185
186
187
188
189
// Language configurations for GitHub Trending Extension
// Language colors mapping
const LANGUAGE_COLORS = {
'Apex': '#1797c0',
'Assembly': '#6E4C13',
'C': '#555555',
'C#': '#239120',
'C++': '#f34b7d',
'Clojure': '#db5855',
'COBOL': '#2c5aa0',
'Crystal': '#000100',
'D': '#ba595e',
'Dart': '#00B4AB',
'F#': '#b845fc',
'Fortran': '#4d41b1',
'Go': '#00ADD8',
'Groovy': '#e69f56',
'Io': '#a9188d',
'Java': '#b07219',
'JavaScript': '#f1e05a',
'Julia': '#a270ba',
'Kotlin': '#A97BFF',
'Lua': '#000080',
'MATLAB': '#e16737',
'Mojo': '#ff4500',
'Nim': '#ffc200',
'Objective-C': '#438eff',
'OCaml': '#3be133',
'Pascal': '#cc4125',
'Perl': '#0298c3',
'PHP': '#4F5D95',
'Python': '#3572A5',
'R': '#198CE7',
'Raku': '#0000fb',
'Ruby': '#701516',
'Rust': '#dea584',
'Swift': '#fa7343',
'TypeScript': '#2b7489',
'Zig': '#ec915c'
};
// Available languages (sorted alphabetically)
const AVAILABLE_LANGUAGES = Object.keys(LANGUAGE_COLORS).sort();
// Default selected languages (these will be loaded by default)
const DEFAULT_SELECTED_LANGUAGES = [
"Python",
"TypeScript",
"C++",
"C",
"Java",
"Go",
"Rust",
"Lua",
];
// Settings keys for chrome storage
const SETTINGS_KEYS = {
SELECTED_LANGUAGES: 'selected_languages',
CUSTOM_LANGUAGES: 'custom_languages',
LANGUAGE_ORDER: 'language_order'
};
// Get language color
function getLanguageColor(language) {
return LANGUAGE_COLORS[language] || '#8b5cf6';
}
// Get default languages configuration
function getDefaultLanguages() {
return DEFAULT_SELECTED_LANGUAGES;
}
// Get all available languages (including custom ones)
async function getAvailableLanguages() {
const customLanguages = await loadCustomLanguages();
const allLanguages = [...AVAILABLE_LANGUAGES, ...customLanguages];
return [...new Set(allLanguages)].sort(); // Remove duplicates and sort
}
// Get predefined languages only
function getPredefinedLanguages() {
return AVAILABLE_LANGUAGES;
}
// Save selected languages to storage
async function saveSelectedLanguages(selectedLanguages) {
return new Promise(resolve => {
chrome.storage.local.set({
[SETTINGS_KEYS.SELECTED_LANGUAGES]: selectedLanguages
}, resolve);
});
}
// Load selected languages from storage
async function loadSelectedLanguages() {
return new Promise(resolve => {
chrome.storage.local.get(SETTINGS_KEYS.SELECTED_LANGUAGES, result => {
const selected = result[SETTINGS_KEYS.SELECTED_LANGUAGES];
resolve(selected || DEFAULT_SELECTED_LANGUAGES);
});
});
}
// Save custom languages to storage
async function saveCustomLanguages(customLanguages) {
return new Promise(resolve => {
chrome.storage.local.set({
[SETTINGS_KEYS.CUSTOM_LANGUAGES]: customLanguages
}, resolve);
});
}
// Load custom languages from storage
async function loadCustomLanguages() {
return new Promise(resolve => {
chrome.storage.local.get(SETTINGS_KEYS.CUSTOM_LANGUAGES, result => {
const custom = result[SETTINGS_KEYS.CUSTOM_LANGUAGES];
resolve(custom || []);
});
});
}
// Add a custom language
async function addCustomLanguage(languageName) {
if (!languageName || languageName.trim() === '') {
throw new Error('Language name cannot be empty');
}
const trimmedName = languageName.trim();
const customLanguages = await loadCustomLanguages();
// Check if language already exists (in predefined or custom)
if (AVAILABLE_LANGUAGES.includes(trimmedName) || customLanguages.includes(trimmedName)) {
throw new Error('Language already exists');
}
customLanguages.push(trimmedName);
await saveCustomLanguages(customLanguages);
return trimmedName;
}
// Remove a custom language
async function removeCustomLanguage(languageName) {
const customLanguages = await loadCustomLanguages();
const filteredLanguages = customLanguages.filter(lang => lang !== languageName);
await saveCustomLanguages(filteredLanguages);
}
// Save language display order to storage
async function saveLanguageOrder(order) {
return new Promise(resolve => {
chrome.storage.local.set({
[SETTINGS_KEYS.LANGUAGE_ORDER]: order
}, resolve);
});
}
// Load language display order from storage
async function loadLanguageOrder() {
return new Promise(resolve => {
chrome.storage.local.get(SETTINGS_KEYS.LANGUAGE_ORDER, result => {
const order = result[SETTINGS_KEYS.LANGUAGE_ORDER];
resolve(order || null);
});
});
}
// Export for use in other files
if (typeof window !== 'undefined') {
window.LanguageSettings = {
getLanguageColor,
getDefaultLanguages,
getAvailableLanguages,
getPredefinedLanguages,
saveSelectedLanguages,
loadSelectedLanguages,
saveCustomLanguages,
loadCustomLanguages,
addCustomLanguage,
removeCustomLanguage,
saveLanguageOrder,
loadLanguageOrder,
LANGUAGE_COLORS,
AVAILABLE_LANGUAGES,
DEFAULT_SELECTED_LANGUAGES
};
}