-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMoreChatGLM.js
655 lines (573 loc) · 27.9 KB
/
MoreChatGLM.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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
// ==UserScript==
// @name MoreChatGLM
// @namespace http://tampermonkey.net/
// @version 1.0.0
// @description MoreChatGLM 是一款专为 智谱清言(ChatGLM )平台设计的用户脚本,旨在优化用户界面,增强功能体验。脚本支持以下功能:对话滚动条、聊天气泡样、宽屏对话、清空内容快捷按钮、内容脱敏快捷按钮、内容脱敏功能配置,以及简洁的浮动菜单便捷操作。此脚本提升了 ChatGLM 的美观性与易用性,让聊天更愉快、更高效。
// @author DD1024z
// @match https://chatglm.cn/*
// @icon https://chatglm.cn/img/icons/favicon.ico
// @license Apache License 2.0
// @grant GM_addStyle
// @grant GM_xmlhttpRequest
// @grant GM_info
// @downloadURL https://update.greasyfork.org/scripts/523195/MoreChatGLM.user.js
// @updateURL https://update.greasyfork.org/scripts/523195/MoreChatGLM.meta.js
// ==/UserScript==
(function () {
'use strict';
const APP_NAME = 'MoreChatGLM';
const defaultConfig = {
displayContentScroll: true,
displayWideScreen: true,
displayChatBubble: true,
displayTopicPopoverMenu: true,
displayClearButton: true,
displaySanitizeButton: true,
sanitizationRules: [
"[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])(\\d{4}|\\d{3}[Xx])->${身份证号码}",
"(0|86|17951)?(13[0-9]|15[0-35-9]|166|17[3-8]|18[0-9]|14[5-79]|19[0-9])[-]?[0-9]{4}[-]?[0-9]{4}->${手机号码}",
"(0\\d{2,3}-?\\d{7,8})->${座机号码}",
"https?:\\/\\/([a-zA-Z0-9_-]+\\.?)+(:\\d+)?(\\/.*)?->${链接}",
"\\w+([-+.\\w])*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*->${电子邮箱}",
"这是匹配的长内容->短内容"
]
};
const config = (() => {
const savedConfig = JSON.parse(localStorage.getItem(APP_NAME));
return { ...defaultConfig, ...savedConfig };
})();
function saveConfig(updatedConfig) {
localStorage.setItem(APP_NAME, JSON.stringify(updatedConfig));
}
function observeDOMChanges(callback, target = document.body, config = { childList: true, subtree: true }) {
const observer = new MutationObserver(callback);
const observerConfig = config;
observer.observe(target, observerConfig);
return observer;
}
const menuItems = [
{ text: '对话滚动条', action: applyContentScroll, checked: config.displayContentScroll },
{ text: '聊天气泡', action: applyChatBubble, checked: config.displayChatBubble },
{ text: '宽屏对话', action: applyWideScreen, checked: config.displayWideScreen },
{ text: '最近对话防误删', action: applyTopicPopoverMenu, checked: config.displayTopicPopoverMenu },
{ text: '清空内容快捷按钮', action: applyClearButton, checked: config.displayClearButton },
{ text: '内容脱敏快捷按钮', action: applySanitizeButton, checked: config.displaySanitizeButton },
{ text: '内容脱敏规则配置', action: showModalDataSanitization },
{ text: '检查更新', action: checkForUpdates },
{ text: '赞赏鼓励', action: showModalAppreciate },
{ text: '关于', action: () => window.open('https://github.com/10D24D/MoreChatGLM', '_blank') },
];
function addFloatingMenu() {
const asideHeader = document.querySelector('div.aside-header');
if (!asideHeader) return;
const triggerDiv = document.createElement('div');
triggerDiv.id = APP_NAME + '-menu-trigger';
triggerDiv.textContent = APP_NAME;
triggerDiv.style.background = '#007BFF';
triggerDiv.style.color = '#FFFFFF';
triggerDiv.style.padding = '10px';
triggerDiv.style.marginTop = '10px';
triggerDiv.style.borderRadius = '5px';
triggerDiv.style.cursor = 'pointer';
triggerDiv.style.textAlign = 'center';
triggerDiv.style.transition = 'background 0.3s';
triggerDiv.style.width = '90%';
triggerDiv.style.boxShadow = '0 2px 4px rgba(0, 0, 0, 0.2)';
triggerDiv.style.fontSize = '14px';
triggerDiv.style.position = 'relative';
const menuPanel = document.createElement('div');
menuPanel.id = APP_NAME + '-menu-panel';
menuPanel.style.position = 'absolute';
menuPanel.style.top = '88px';
menuPanel.style.left = '13px';
menuPanel.style.background = '#FFFFFF';
menuPanel.style.boxShadow = '0 2px 8px rgba(0, 0, 0, 0.2)';
menuPanel.style.borderRadius = '5px';
menuPanel.style.padding = '10px';
menuPanel.style.zIndex = '1000';
menuPanel.style.width = '192px';
menuPanel.classList = 'hidden';
menuItems.forEach(item => {
const menuItem = document.createElement('div');
menuItem.style.display = 'flex';
menuItem.style.alignItems = 'center';
menuItem.style.justifyContent = 'space-between';
menuItem.style.padding = '5px 10px';
menuItem.style.cursor = 'pointer';
menuItem.style.borderBottom = '1px solid #DDDDDD';
menuItem.style.height = '25px';
menuItem.style.transition = 'background-color 0.3s';
menuItem.onmouseover = () => {
menuItem.style.backgroundColor = '#F1F2F3';
};
menuItem.onmouseout = () => {
menuItem.style.backgroundColor = '#FFFFFF';
};
const itemText = document.createElement('span');
itemText.textContent = item.text;
menuItem.appendChild(itemText);
if (item.hasOwnProperty('checked')) {
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.checked = item.checked;
checkbox.style.width = '20px';
checkbox.style.height = '20px';
checkbox.style.cursor = 'pointer';
checkbox.onchange = () => {
item.checked = checkbox.checked;
item.action(item.checked);
};
menuItem.appendChild(checkbox);
} else {
menuItem.onclick = () => {
item.action();
};
}
menuPanel.appendChild(menuItem);
});
triggerDiv.addEventListener('mouseenter', () => {
menuPanel.classList.remove('hidden');
});
triggerDiv.addEventListener('mouseleave', (e) => {
if (!menuPanel.contains(e.relatedTarget)) {
menuPanel.classList.add('hidden');
}
});
menuPanel.addEventListener('mouseleave', (e) => {
if (!triggerDiv.contains(e.relatedTarget)) {
menuPanel.classList.add('hidden');
}
});
asideHeader.parentElement.insertBefore(triggerDiv, asideHeader.nextSibling);
asideHeader.parentElement.insertBefore(menuPanel, asideHeader.nextSibling);
const aside = asideHeader.closest('aside');
observeDOMChanges(() => {
if (aside.classList.contains('collapse-aside')) {
triggerDiv.classList.add('hidden');
} else {
triggerDiv.classList.remove('hidden');
}
}, aside, { attributes: true, attributeFilter: ['class'] })
}
function updateDisplayConfig(key, isChecked = false) {
config[key] = isChecked;
saveConfig(config);
}
function applyContentScroll(isChecked = false) {
updateDisplayConfig('displayContentScroll', isChecked)
const container = document.querySelector('.conversation-list');
if (container) {
if (isChecked) {
container.classList.remove('scroll-display-none');
} else {
container.classList.add('scroll-display-none');
}
console.log('ContentScroll:', isChecked);
}
};
function applyWideScreen(isChecked = false) {
updateDisplayConfig('displayWideScreen', isChecked);
let wideScreenStyle = document.getElementById(APP_NAME + '-wide-screen-style');
if (!wideScreenStyle) {
wideScreenStyle = document.createElement('style');
wideScreenStyle.id = APP_NAME + '-wide-screen-style';
document.head.appendChild(wideScreenStyle);
}
if (isChecked) {
let dynamicStyles = `
.markdown-body, .conversation-item, .interact-operate, .component-box-new {
max-width: 100% !important;
margin: 0 auto !important;
}
`;
const uniqueItemAttributes = new Set();
document.querySelectorAll('.dialogue .detail .item').forEach(item => {
const dynamicAttribute = Array.from(item.attributes).find(attr => attr.name.startsWith('data-v-'));
if (dynamicAttribute) {
uniqueItemAttributes.add(dynamicAttribute.name);
}
});
if (uniqueItemAttributes.size > 0) {
uniqueItemAttributes.forEach(attr => {
dynamicStyles += `
.dialogue .detail .item[${attr}] {
max-width: 100% !important;
}
`;
});
} else {
dynamicStyles += `
.dialogue .detail .item {
max-width: 100% !important;
}
`;
}
const uniqueBottomAttributes = new Set();
document.querySelectorAll('.conversation-bottom').forEach(bottom => {
const dynamicAttribute = Array.from(bottom.attributes).find(attr => attr.name.startsWith('data-v-'));
if (dynamicAttribute) {
uniqueBottomAttributes.add(dynamicAttribute.name);
}
});
if (uniqueBottomAttributes.size > 0) {
uniqueBottomAttributes.forEach(attr => {
dynamicStyles += `
.conversation-bottom[${attr}], .dialogue .conversation-bottom[${attr}] {
max-width: 100% !important;
}
`;
});
} else {
dynamicStyles += `
.conversation-bottom, .dialogue .conversation-bottom {
max-width: 100% !important;
}
`;
}
wideScreenStyle.textContent = dynamicStyles.replace(/\s+/g, ' ').trim();
} else {
wideScreenStyle.textContent = '';
}
console.log('WideScreen:', isChecked);
}
function applyTopicPopoverMenu(isChecked = false) {
updateDisplayConfig('displayTopicPopoverMenu', isChecked);
let menuStyleElement = document.getElementById(APP_NAME + '-topic-menu-style');
if (!menuStyleElement) {
menuStyleElement = document.createElement('style');
menuStyleElement.id = APP_NAME + '-topic-menu-style';
document.head.appendChild(menuStyleElement);
}
if (isChecked) {
const topicPopoverMenus = document.querySelectorAll('.history-item');
const uniqueAttributes = new Set();
topicPopoverMenus.forEach(item => {
const dynamicAttribute = Array.from(item.attributes).find(attr => attr.name.startsWith('data-v-'));
if (dynamicAttribute) {
uniqueAttributes.add(dynamicAttribute.name);
}
});
let dynamicStyles = '';
if (uniqueAttributes.size > 0) {
uniqueAttributes.forEach(attr => {
dynamicStyles += `
.history-item[${attr}] .el-popper {
display: none !important;
}
`;
});
} else {
dynamicStyles = `
.history-item .el-popper {
display: none !important;
}
`;
}
menuStyleElement.textContent = dynamicStyles.replace(/\s+/g, ' ').trim();
} else {
menuStyleElement.textContent = '';
}
console.log('TopicPopoverMenu:', isChecked);
}
function applyChatBubble(isChecked = false) {
updateDisplayConfig('displayChatBubble', isChecked);
let bubbleStyleElement = document.getElementById(APP_NAME + '-chat-bubble-style');
if (!bubbleStyleElement) {
bubbleStyleElement = document.createElement('style');
bubbleStyleElement.id = APP_NAME + '-chat-bubble-style';
document.head.appendChild(bubbleStyleElement);
}
if (isChecked) {
const bubbleStyles = `
div.question-text-style {
background-color: #DEEDD7;
border-radius: 0.5rem;
padding: 0.75rem 0.5rem;
margin-left: 12px;
max-width: 100%;
}
div.markdown-body {
background-color: #F1F2F3;
border-radius: 0.5rem;
padding: 0.75rem 1.25rem;
max-width: 100%;
}
`;
bubbleStyleElement.textContent = bubbleStyles.replace(/\s+/g, ' ').trim();
hideEmptyMarkdownBodies();
} else {
bubbleStyleElement.textContent = '';
}
console.log('ChatBubble:', isChecked);
}
function hideEmptyMarkdownBodies() {
const markdownBodies = document.querySelectorAll('div.markdown-body');
markdownBodies.forEach(body => {
if (!body.textContent.trim()) {
body.style.display = 'none';
} else {
body.style.display = '';
}
});
}
const verInt = function (vs) {
const vl = vs.split('.');
let vi = 0;
for (let i = 0; i < vl.length && i < 3; i++) {
vi += parseInt(vl[i]) * (1000 ** (2 - i));
}
return vi;
};
function checkForUpdates(action = "click") {
const downloadURL = `https://raw.githubusercontent.com/10D24D/MoreChatGLM/main/MoreChatGLM.js`;
const updateURL = downloadURL;
GM_xmlhttpRequest({
method: "GET",
url: `${updateURL}?t=${Date.now()}`,
onload: function (response) {
const crv = GM_info.script.version;
const m = response.responseText.match(/@version\s+(\S+)/);
const ltv = m && m[1];
if (ltv && verInt(ltv) > verInt(crv)) {
alert('发现新版本')
window.open(`${downloadURL}?t=${Date.now()}`, '_blank');
} else {
if (action === "click") {
alert('已是最新版')
}
}
}
});
};
function showModalAppreciate() {
const existingModal = document.getElementById(APP_NAME + '-appreciate-modal');
if (existingModal) {
existingModal.style.display = 'block';
return;
}
const modal = document.createElement('div');
modal.id = APP_NAME + '-appreciate-modal';
modal.style.position = 'fixed';
modal.style.top = '50%';
modal.style.left = '50%';
modal.style.transform = 'translate(-50%, -50%)';
modal.style.width = '80%';
modal.style.maxWidth = '500px';
modal.style.backgroundColor = '#FFFFFF';
modal.style.borderRadius = '8px';
modal.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
modal.style.overflow = 'hidden';
modal.style.zIndex = '1000';
modal.innerHTML = `
<div style="padding: 16px; border-bottom: 1px solid #DDDDDD; display: flex; justify-content: space-between; align-items: center;">
<h2 style="margin: 0; font-size: 18px; color: #333333;">赞赏鼓励</h2>
</div>
<div style="padding: 16px;">
<p style="margin: 0 0 16px; color: #555555; font-size: 14px;">本项目由兴趣驱使,优化用户界面,增强功能体验,并共享世界。<br>如果你喜欢作者的项目,可以给作者一个免费的Star或者Follow。</p>
<img src="https://raw.githubusercontent.com/10D24D/MoreChatGLM/main/static/appreciate_wechat.jpg" style="display: block; max-width: 100%; height: auto; margin: 0 auto 16px;">
<div style="display: flex; gap: 8px; justify-content: flex-end;">
<button style="padding: 8px 16px; background-color: #007BFF; color: #FFFFFF; border: none; border-radius: 4px; cursor: pointer;" onclick="window.open('https://github.com/10D24D/MoreChatGLM?tab=readme-ov-file#%E8%B5%9E%E8%B5%8F%E9%BC%93%E5%8A%B1')">更多鼓励方式</button>
<button style="padding: 8px 16px; background-color: #F0F0F0; color: #333333; border: none; border-radius: 4px; cursor: pointer;" onclick="document.getElementById('${modal.id}').style.display = 'none';">取消</button>
</div>
</div>
`;
document.body.appendChild(modal);
}
function validateRules(rules) {
return rules.every(rule => {
const [regex, replacement] = rule.split('->').map(item => item.trim());
try {
new RegExp(regex);
return !!replacement;
} catch {
return false;
}
});
}
function applyDataSanitizationRules() {
const inputBox = document.querySelector('#search-input-box div.input-box-inner textarea');
if (!inputBox) {
alert('未找到输入框');
return;
}
let content = inputBox.value;
config.sanitizationRules.forEach(rule => {
const [regex, replacement] = rule.split('->').map(item => item.trim());
if (regex && replacement) {
try {
const regexObj = new RegExp(regex, 'g');
content = content.replace(regexObj, replacement);
} catch (error) {
console.error('Invalid regex:', regex, error);
}
}
});
inputBox.value = content;
inputBox.dispatchEvent(new Event('input', { bubbles: true }));
}
function showModalDataSanitization() {
const modalId = APP_NAME + '-data-sanitization-modal';
let modal = document.getElementById(modalId);
if (modal) {
modal.querySelector('#' + APP_NAME + '-data-sanitization-rules').value = config.sanitizationRules.join('\n');
modal.style.display = 'block';
return;
}
modal = document.createElement('div');
modal.id = modalId;
modal.style.position = 'fixed';
modal.style.top = '50%';
modal.style.left = '50%';
modal.style.transform = 'translate(-50%, -50%)';
modal.style.width = '80%';
modal.style.maxWidth = '500px';
modal.style.backgroundColor = '#FFFFFF';
modal.style.borderRadius = '8px';
modal.style.boxShadow = '0 4px 6px rgba(0, 0, 0, 0.1)';
modal.style.overflow = 'hidden';
modal.style.zIndex = '1000';
modal.innerHTML = `
<div style="padding: 16px; border-bottom: 1px solid #DDDDDD; display: flex; justify-content: space-between; align-items: center;">
<h2 style="margin: 0; font-size: 18px; color: #333333;">内容脱敏规则配置</h2>
</div>
<div style="padding: 16px;">
<p style="margin: 0 0 16px; color: #555555; font-size: 14px; text-align: left; line-height: 20px;">本功能会将聊天输入框里的敏感内容进行脱敏<br>请根据正则表达式语法编写内容脱敏规则,不同的规则用换行间隔。<br>格式:匹配内容(正则表达式)->替换内容</p>
<textarea id="${APP_NAME + '-data-sanitization-rules'}" style="width: 95%; height: 10rem; resize: none; border-radius: 4px; padding: 10px; background-color: #F9F9F9; border: 1px solid #DDDDDD;">${config.sanitizationRules.join('\n')}</textarea>
<div style="margin-top: 20px; display: flex; justify-content: flex-end; gap: 10px;">
<button id="${APP_NAME + '-reset-rules-button'}" style="padding: 10px 20px; background-color: #28A745; color: white; border: none; border-radius: 4px; cursor: pointer;">恢复默认规则</button>
<button id="${APP_NAME + '-save-rules-button'}" style="padding: 10px 20px; background-color: #007BFF; color: white; border: none; border-radius: 4px; cursor: pointer;">保存</button>
<button style="padding: 10px 20px; background-color: #F0F0F0; color: #333333; border: none; border-radius: 4px; cursor: pointer;" onclick="document.getElementById('${modalId}').style.display = 'none';">取消</button>
</div>
</div>
`;
document.body.appendChild(modal);
document.getElementById(APP_NAME + '-save-rules-button').addEventListener('click', () => {
const rulesText = document.getElementById(APP_NAME + '-data-sanitization-rules').value;
const updatedRules = rulesText.split('\n').filter(rule => rule.trim() !== '');
if (validateRules(updatedRules)) {
config.sanitizationRules = updatedRules;
saveConfig(config);
alert('规则已保存!');
modal.style.display = 'none';
} else {
alert('规则格式不正确,请检查并重试!');
}
});
document.getElementById(APP_NAME + '-reset-rules-button').addEventListener('click', () => {
config.sanitizationRules = [...defaultConfig.sanitizationRules];
saveConfig(config);
document.getElementById(APP_NAME + '-data-sanitization-rules').value = config.sanitizationRules.join('\n');
alert('已恢复默认规则!');
});
}
function clearInputBoxContent() {
const inputBox = document.querySelector('#search-input-box div.input-box-inner textarea');
if (!inputBox) {
alert('未找到输入框');
return;
}
inputBox.value = '';
inputBox.dispatchEvent(new Event('input', { bubbles: true }));
}
function applyClearButton(isChecked = false) {
updateDisplayConfig('displayClearButton', isChecked);
const inputWrap = document.querySelector('#search-input-box div.input-wrap');
if (!inputWrap) return;
let clearButton = document.querySelector('#' + APP_NAME + '-clear-button');
let sanitizeButton = document.querySelector('#' + APP_NAME + '-sanitize-button');
const enterIcon = inputWrap.querySelector('.enter img.enter_icon');
if (isChecked) {
if (!clearButton) {
clearButton = document.createElement('button');
clearButton.id = APP_NAME + '-clear-button';
clearButton.textContent = '清空内容';
clearButton.style.backgroundColor = '#FB5531';
clearButton.style.color = '#FFFFFF';
clearButton.style.border = 'none';
clearButton.style.borderRadius = '4px';
clearButton.style.cursor = 'pointer';
clearButton.style.height = '30px';
clearButton.style.width = '70px';
clearButton.onclick = clearInputBoxContent;
const clearButtonWrapper = document.createElement('div');
clearButtonWrapper.className = 'enter';
clearButtonWrapper.style.marginRight = '10px';
clearButtonWrapper.style.alignSelf = 'flex-end';
clearButtonWrapper.appendChild(clearButton);
if (sanitizeButton) {
sanitizeButton.parentNode.before(clearButtonWrapper);
} else if (enterIcon) {
enterIcon.parentNode.before(clearButtonWrapper);
} else {
inputWrap.appendChild(clearButtonWrapper);
}
}
} else {
if (clearButton) {
clearButton.parentElement.remove();
}
}
console.log('ClearButton:', isChecked);
}
function applySanitizeButton(isChecked = false) {
updateDisplayConfig('displaySanitizeButton', isChecked);
const inputWrap = document.querySelector('#search-input-box div.input-wrap');
if (!inputWrap) return;
let sanitizeButton = document.querySelector('#' + APP_NAME + '-sanitize-button');
const enterIcon = inputWrap.querySelector('.enter img.enter_icon');
if (isChecked) {
if (!sanitizeButton) {
sanitizeButton = document.createElement('button');
sanitizeButton.id = APP_NAME + '-sanitize-button';
sanitizeButton.textContent = '内容脱敏';
sanitizeButton.style.backgroundColor = '#288C8C';
sanitizeButton.style.color = '#FFFFFF';
sanitizeButton.style.border = 'none';
sanitizeButton.style.borderRadius = '4px';
sanitizeButton.style.cursor = 'pointer';
sanitizeButton.style.height = '30px';
sanitizeButton.style.width = '70px';
sanitizeButton.onclick = applyDataSanitizationRules;
const sanitizeButtonWrapper = document.createElement('div');
sanitizeButtonWrapper.className = 'enter';
sanitizeButtonWrapper.style.marginRight = '10px';
sanitizeButtonWrapper.style.alignSelf = 'flex-end';
sanitizeButtonWrapper.appendChild(sanitizeButton);
if (enterIcon) {
enterIcon.parentNode.before(sanitizeButtonWrapper);
} else {
inputWrap.appendChild(sanitizeButtonWrapper);
}
}
} else {
if (sanitizeButton) {
sanitizeButton.parentElement.remove();
}
}
console.log('SanitizeButton:', isChecked);
}
function init() {
addFloatingMenu();
applyContentScroll(config.displayContentScroll);
applyWideScreen(config.displayWideScreen);
applyChatBubble(config.displayChatBubble);
applyTopicPopoverMenu(config.displayTopicPopoverMenu);
applyClearButton(config.displayClearButton);
applySanitizeButton(config.displaySanitizeButton);
observeDOMChanges(() => {
requestAnimationFrame(() => {
if (config.displayContentScroll) applyContentScroll(true);
if (config.displayWideScreen) applyWideScreen(true);
if (config.displayChatBubble) applyChatBubble(true);
if (config.displayClearButton) applyClearButton(true);
if (config.displaySanitizeButton) applySanitizeButton(true);
});
});
}
window.addEventListener('load', init);
GM_addStyle(`
.hidden {
display: none !important;
}
`);
})();