-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar.js
272 lines (226 loc) · 6.52 KB
/
sidebar.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
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
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
var allowHTML = false;
$('#sidebar').onmouseenter = $('#sidebar').ontouchstart = function (e) {
$('#sidebar-content').classList.remove('hidden');
$('#sidebar').classList.add('expand');
e.stopPropagation();
}
$('#sidebar').onmouseleave = document.ontouchstart = function (event) {
var e = event.toElement || event.relatedTarget;
try {
if (e.parentNode == this || e == this) {
return;
}
} catch (e) { return; }
if (!$('#pin-sidebar').checked) {
$('#sidebar-content').classList.add('hidden');
$('#sidebar').classList.remove('expand');
}
}
$('#clear-messages').onclick = function () {
// Delete children elements
var messages = $('#messages');
messages.innerHTML = '';
}
// Restore settings from localStorage
if (localStorageGet('auto-login') == 'true') {
$('#auto-login').checked = true;
}
if (localStorageGet('pin-sidebar') == 'true') {
$('#pin-sidebar').checked = true;
$('#sidebar-content').classList.remove('hidden');
}
if (localStorageGet('sound-switch') == 'true') {
$('#sound-switch').checked = true;
}
if (localStorageGet('joined-left') == 'false') {
$('#joined-left').checked = false;
}
$('#pin-sidebar').onchange = function (e) {
localStorageSet('pin-sidebar', !!e.target.checked);
}
$('#joined-left').onchange = function (e) {
localStorageSet('joined-left', !!e.target.checked);
}
$('#parse-latex').onchange = function (e) {
if ( e.target.checked ) {
md.inline.ruler.enable([ 'katex' ]);
md.block.ruler.enable([ 'katex' ]);
} else {
md.inline.ruler.disable([ 'katex' ]);
md.block.ruler.disable([ 'katex' ]);
}
}
if (localStorageGet('syntax-highlight') == 'false') {
$('#syntax-highlight').checked = false;
markdownOptions.doHighlight = false;
}
$('#syntax-highlight').onchange = function (e) {
var enabled = !!e.target.checked;
localStorageSet('syntax-highlight', enabled);
markdownOptions.doHighlight = enabled;
}
if (localStorageGet('allow-imgur') == 'false') {
$('#allow-imgur').checked = false;
allowImages = false;
}
$('#allow-imgur').onchange = function (e) {
var enabled = !!e.target.checked;
localStorageSet('allow-imgur', enabled);
allowImages = enabled;
}
if (localStorageGet('allow-html') == 'true') {
$('#allow-html').checked = true;
allowHTML = true;
}
$('#allow-html').onchange = function (e) {
var enabled = !!e.target.checked;
if ( !!e.target.checked ) {
pushMessage({ nick: '!', text: '查看HTML消息有可能降低聊天室的安全性和体验,如果遇到让您不适的情况,您可以选择 清空本页聊天记录'});
}
localStorageSet('allow-html', enabled);
allowHTML = enabled;
}
// User list
var onlineUsers = [];
var ignoredUsers = [];
function userAdd(nick) {
var user = document.createElement('a');
user.textContent = nick;
user.onclick = function (e) {
userInvite(nick)
}
user.oncontextmenu = function (e) {
userIgnore(nick)
}
var userLi = document.createElement('li');
userLi.appendChild(user);
$('#users').appendChild(userLi);
onlineUsers.push(nick);
}
function userRemove(nick) {
var users = $('#users');
var children = users.children;
for (var i = 0; i < children.length; i++) {
var user = children[i];
if (user.textContent == nick) {
users.removeChild(user);
}
}
var index = onlineUsers.indexOf(nick);
if (index >= 0) {
onlineUsers.splice(index, 1);
}
}
function usersClear() {
var users = $('#users');
while (users.firstChild) {
users.removeChild(users.firstChild);
}
onlineUsers.length = 0;
}
function userInvite(nick) {
send({ cmd: 'invite', nick: nick });
}
function userIgnore(nick) {
if (nick == myNick) {
pushMessage({nick: '!', trip: '/Error', text: `你不能屏蔽你自己!`});
return;
}
var index = ignoredUsers.indexOf(nick);
if (index >= 0) {
ignoredUsers.splice(index, 1);
pushMessage({nick: '*', trip: 'Ignore', text: `已取消屏蔽 @${nick}。`});
}
else {
ignoredUsers.push(nick);
pushMessage({nick: '*', trip: 'Ignore', text: `已屏蔽 @${nick}。`});
}
}
/* color scheme switcher */
var schemes = [
'Atelier - Dune',
'黑色系 - 寒夜',
'黑色系 - 都市',
'黑色系 - 荧黄',
'青色系 - 初夏',
'黑色系 - 晨雾',
'黑色系 - 新春',
'白色系 - 入冬',
'测试主题'
];
var highlights = [
'agate',
'androidstudio',
'atom-one-dark',
'darcula',
'github',
'rainbow',
'tomorrow',
'xcode',
'zenburn'
]
var currentScheme = 'Atelier - Dune';
var currentHighlight = 'darcula';
function setScheme(scheme) {
currentScheme = scheme;
if (scheme == 'Atelier - Dune'){
$('#scheme-link').href = "scheme.css";
} else {
$('#scheme-link').href = "https://crosst.chat/schemes/" + scheme + ".css";
}
switch (scheme) {
case 'Atelier - Dune': setHighlight('darcula');
break;
case '黑色系 - 寒夜': setHighlight('rainbow');
break;
case '青色系 - 初夏': setHighlight('tomorrow');
break;
case '黑色系 - 都市': setHighlight('atom-one-dark');
break;
case '黑色系 - 荧黄': setHighlight('zenburn');
break;
case '黑色系 - 新春': setHighlight('zenburn');
break;
case '黑色系 - 晨雾': setHighlight('rainbow');
break;
case '白色系 - 入冬': setHighlight('xcode');
break;
}
localStorageSet('scheme', scheme);
}
function setHighlight(scheme) {
currentHighlight = scheme;
$('#highlight-link').href = "https://crosst.chat/vendor/hljs/styles/" + scheme + ".min.css";
localStorageSet('highlight', scheme);
}
// Add scheme options to dropdown selector
schemes.forEach(function (scheme) {
var option = document.createElement('option');
option.textContent = scheme;
option.value = scheme;
$('#scheme-selector').appendChild(option);
});
highlights.forEach(function (scheme) {
var option = document.createElement('option');
option.textContent = scheme;
option.value = scheme;
$('#highlight-selector').appendChild(option);
});
$('#sound-switch').onchange = function (e) {
localStorageSet('sound-switch', !!e.target.checked);
}
$('#scheme-selector').onchange = function (e) {
setScheme(e.target.value);
}
$('#highlight-selector').onchange = function (e) {
setHighlight(e.target.value);
}
// Load sidebar configaration values from local storage if available
if (localStorageGet('scheme')) {
setScheme(localStorageGet('scheme'));
}
if (localStorageGet('highlight')) {
setHighlight(localStorageGet('highlight'));
}
$('#scheme-selector').value = currentScheme;
$('#highlight-selector').value = currentHighlight;