-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
2302 lines (2301 loc) · 107 KB
/
main.js
File metadata and controls
2302 lines (2301 loc) · 107 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
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
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// ==UserScript==
// @name 🏆 LINUX DO OAuth 极简助手 - 面板集成版 (无自动点击)
// @namespace https://github.com/TechnologyStar/linuxdo-oauth-helper
// @version 3.0.3
// @description 🎯 专为LINUX DO OAuth设计的三主题UI助手 - 简约白/紫色渐变/彩虹华丽 + 条形图统计 (已移除自动点击功能)
// @author Premium UI Designer
// @match https://connect.linux.do/*
// @grant GM_setValue
// @grant GM_getValue
// @grant GM_addStyle
// @grant GM_registerMenuCommand
// @grant GM_notification
// @grant GM_openInTab
// @grant GM_download
// @license MIT
// @icon data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHZpZXdCb3g9IjAgMCA2NCA2NCIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj48cmVjdCB3aWR0aD0iNjQiIGhlaWdodD0iNjQiIHJ4PSIyMCIgZmlsbD0iI0ZGRkZGRiIgc3Ryb2tlPSIjRTVFN0VCIiBzdHJva2Utd2lkdGg9IjIiLz48dGV4dCB4PSIzMiIgeT0iNDAiIGZvbnQtZmFtaWx5PSJzeXN0ZW0tdWkiIGZvbnQtc2l6ZT0iMjQiIGZpbGw9IiM2QjdCODAiIHRleHQtYW5jaG9yPSJtaWRkbGUiPvCfkpA8L3RleHQ+PC9zdmc+
// @downloadURL https://update.greasyfork.org/scripts/544675/%F0%9F%8F%86%20LINUX%20DO%20OAuth%20%E6%9E%81%E7%AE%80%E5%8A%A9%E6%89%8B%20-%20%E9%9D%A2%E6%9D%BF%E9%9B%86%E6%88%90%E7%89%88.user.js
// @updateURL https://update.greasyfork.org/scripts/544675/%F0%9F%8F%86%20LINUX%20DO%20OAuth%20%E6%9E%81%E7%AE%80%E5%8A%A9%E6%89%8B%20-%20%E9%9D%A2%E6%9D%BF%E9%9B%86%E6%88%90%E7%89%88.meta.js
// ==/UserScript==
(function() {
'use strict';
// ================== 配置 ==================
const CONFIG = {
version: '3.2.0',
github: 'https://github.com/TechnologyStar/linuxdo-oauth-helper',
defaultSettings: {
// 核心功能
// autoClickApprove: false, // ❌ 已移除:自动点击授权
saveLoginHistory: true,
showNotifications: false,
// 网站限制
// restrictByWebsite: true, // ❌ 已移除:默认开启限制:只对白名单网站自动授权
// useRemoteWhitelist: true, // ❌ 已移除:默认启用远程白名单
// remoteWhitelistUrl: 'https://raw.githubusercontent.com/TechnologyStar/linuxdo-oauth-helper/refs/heads/main/whitelist.json', // ❌ 已移除
// remoteWhitelistTtlMs: 6 * 60 * 60 * 1000, // ❌ 已移除:远程名单缓存时长:6小时
// whitelist: [], // ❌ 已移除:本地额外白名单(可选,手动补充)
// UI设置
autoHidePanel: false,
enablePageStyling: true,
theme: 'light',
uiTheme: 'minimal-white',
// 高级功能
autoExportData: false,
checkForUpdates: true,
enableAdvancedStats: false,
enableDebugMode: false,
showChartStats: true, // 显示图表统计
showHourlyChart: true, // 显示小时统计
showWebsiteStats: true, // 显示网站统计
// 时间设置
// autoClickDelay: 10, // ❌ 已移除:自动点击延迟
notificationDuration: 3000,
panelPosition: 'top-right'
},
selectors: {
// approveButton: 'a.bg-red-500[href*="/oauth2/approve/"]', // ❌ 已移除:自动点击相关选择器
declineButton: 'a.bg-blue-500[href*="/oauth2/decline/"]',
userInfo: 'h1.text-2xl'
},
themes: {
light: {
primary: '#ffffff',
secondary: '#f9fafb',
accent: '#10b981',
text: '#111827',
border: '#e5e7eb'
},
dark: {
primary: '#1f2937',
secondary: '#111827',
accent: '#34d399',
text: '#f9fafb',
border: '#374151'
}
},
uiThemes: {
'minimal-white': {
name: '简约白',
description: '极简白色设计,清爽简洁',
icon: '⚪',
colors: {
panelBg: '#ffffff',
panelBorder: '#e5e7eb',
triggerBg: '#ffffff',
accent: '#10b981',
text: '#111827',
textMuted: '#6b7280'
}
},
'purple-gradient': {
name: '紫色渐变',
description: '基于OAuth页面的紫色渐变设计',
icon: '🟣',
colors: {
panelBg: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
panelBorder: 'rgba(255,255,255,0.2)',
triggerBg: 'linear-gradient(135deg, #667eea 0%, #764ba2 100%)',
accent: '#4c51bf',
text: '#ffffff',
textMuted: 'rgba(255,255,255,0.8)'
}
},
'rainbow-fancy': {
name: '彩虹华丽',
description: '炫酷多彩动画设计,视觉冲击',
icon: '🌈',
colors: {
panelBg: 'linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab)',
panelBorder: 'rgba(255,255,255,0.3)',
triggerBg: 'linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab)',
accent: '#ff6b6b',
text: '#ffffff',
textMuted: 'rgba(255,255,255,0.9)'
}
}
}
};
// ================== 工具函数 ==================
class Utils {
static log(message, type = 'info') {
const settings = window.oauthHelper?.storage?.getSettings() || {};
if (settings.enableDebugMode || type === 'error') {
console.log(`%c[OAuth Helper] ${message}`,
type === 'error' ? 'color: red' : 'color: #10B981',
new Date().toLocaleTimeString()
);
}
}
static formatDate(date) {
return new Date(date).toLocaleString('zh-CN');
}
static generateId() {
return Date.now() + '-' + Math.random().toString(36).substr(2, 6);
}
static debounce(func, wait) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func.apply(this, args), wait);
};
}
static formatBytes(bytes) {
if (bytes === 0) return '0 Bytes';
const k = 1024;
const sizes = ['Bytes', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
// ✅ 规范化:输入 URL 或 文本 → 纯域名(不带协议、不带路径、不带末尾/)
static normalizeHost(input = '') {
if (!input) return '';
let s = String(input).trim();
// 先去协议、末尾斜杠、路径
s = s.replace(/^https?:\/\//i, '').replace(/\/+$/g, '');
s = s.split('/')[0];
return s.toLowerCase();
}
// ✅ 远程抓取文本(优先 GM_xmlhttpRequest,失败再用 fetch)
static fetchText(url) {
return new Promise((resolve, reject) => {
if (typeof GM_xmlhttpRequest === 'function') {
GM_xmlhttpRequest({
method: 'GET',
url,
headers: { 'Cache-Control': 'no-cache' },
timeout: 15000,
onload: r => resolve(r.responseText),
onerror: e => reject(e && e.error || 'GM_xmlhttpRequest error'),
ontimeout: () => reject('GM_xmlhttpRequest timeout')
});
} else {
fetch(url, { cache: 'no-store' })
.then(res => res.text())
.then(resolve)
.catch(err => reject(err?.message || 'fetch error'));
}
});
}
// ✅ 加载或刷新远程白名单(按行解析,忽略空行和 # 注释)
// 结果会缓存到 Storage 的 remoteWhitelist / remoteWhitelistUpdatedAt
static async loadRemoteWhitelist(storage, settings) {
// ❌ 已移除:相关逻辑
return []; // 返回空数组
}
// ✅ 判断 host 是否在 {远程 | 本地} 白名单(支持 *.example.com)
static isHostAllowed(host, lists = []) {
// ❌ 已移除:相关逻辑
return true; // 默认允许
}
static exportToJSON(data, filename) {
const blob = new Blob([JSON.stringify(data, null, 2)], {
type: 'application/json'
});
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = filename;
a.click();
URL.revokeObjectURL(url);
}
static async importFromJSON(file) {
return new Promise((resolve, reject) => {
const reader = new FileReader();
reader.onload = (e) => {
try {
const data = JSON.parse(e.target.result);
resolve(data);
} catch (error) {
reject(error);
}
};
reader.onerror = reject;
reader.readAsText(file);
});
}
// 生成条形图HTML
static generateBarChart(data, options = {}) {
const {
maxHeight = 80,
barColor = '#10b981',
backgroundColor = '#f3f4f6',
showValues = true,
className = 'oauth-chart-bar'
} = options;
const maxValue = Math.max(...Object.values(data));
if (maxValue === 0) return '<div class="oauth-chart-empty">📊 暂无统计数据</div>';
return Object.entries(data).map(([label, value]) => {
const percentage = (value / maxValue) * 100;
const height = Math.max((percentage / 100) * maxHeight, 4); // 最小高度4px
return `
<div class="oauth-chart-bar-container">
<div class="oauth-chart-bar-wrapper" style="height: ${maxHeight + 5}px;">
<div class="${className}"
style="height: ${height}px; background: ${barColor};"
data-value="${value}" data-label="${label}">
${showValues && value > 0 ? `<span class="oauth-chart-value">${value}</span>` : ''}
</div>
</div>
<div class="oauth-chart-label" title="${label}: ${value}次">${label}</div>
</div>
`;
}).join('');
}
// 生成时间序列数据(最近7天)
static generateTimeSeriesData(history) {
const now = new Date();
const last7Days = {};
// 初始化最近7天
for (let i = 6; i >= 0; i--) {
const date = new Date(now);
date.setDate(date.getDate() - i);
const dateKey = date.toLocaleDateString('zh-CN', { month: '2-digit', day: '2-digit' });
last7Days[dateKey] = 0;
}
// 统计每天的登录次数
history.forEach(record => {
const recordDate = new Date(record.timestamp);
const dateKey = recordDate.toLocaleDateString('zh-CN', { month: '2-digit', day: '2-digit' });
if (last7Days.hasOwnProperty(dateKey)) {
last7Days[dateKey]++;
}
});
return last7Days;
}
// 生成小时统计数据(今天24小时)
static generateHourlyData(history) {
const today = new Date();
const todayStr = today.toDateString();
const hourlyData = {};
// 初始化24小时
for (let i = 0; i < 24; i++) {
const hour = i.toString().padStart(2, '0') + ':00';
hourlyData[hour] = 0;
}
// 统计今天各小时的登录次数
history.forEach(record => {
const recordDate = new Date(record.timestamp);
if (recordDate.toDateString() === todayStr) {
const hour = recordDate.getHours().toString().padStart(2, '0') + ':00';
hourlyData[hour]++;
}
});
return hourlyData;
}
// 生成网站统计数据
static generateWebsiteStats(history) {
const websites = {};
history.forEach(record => {
const website = record.website || '未知网站';
websites[website] = (websites[website] || 0) + 1;
});
// 排序并取前5个
const sortedWebsites = Object.entries(websites)
.sort(([,a], [,b]) => b - a)
.slice(0, 5)
.reduce((obj, [key, value]) => ({ ...obj, [key]: value }), {});
return sortedWebsites;
}
// 生成操作类型统计
static generateActionStats(history) {
const actions = {
// '自动授权': 0, // ❌ 已移除:自动授权统计
'手动授权': 0,
'手动拒绝': 0
};
history.forEach(record => {
// if (record.action === '自动授权') { // ❌ 已移除:自动授权判断
// actions['自动授权']++;
// } else
if (record.action === '手动授权') {
actions['手动授权']++;
} else if (record.action === '手动拒绝') {
actions['手动拒绝']++;
}
});
return actions;
}
}
// ================== 存储管理 ==================
class Storage {
constructor() {
this.prefix = 'loh_';
this.initStorage();
}
initStorage() {
const keys = ['settings', 'stats', 'history', 'metadata']; // ❌ 已移除:'remoteWhitelist', 'remoteWhitelistUpdatedAt'
keys.forEach(key => {
if (this.get(key) === null) {
this.set(key, this.getDefaultValue(key));
}
});
}
getDefaultValue(key) {
const defaults = {
settings: CONFIG.defaultSettings,
stats: {
totalLogins: 0,
// autoClicks: 0, // ❌ 已移除:自动点击统计
manualClicks: 0,
sessionsCount: 0,
lastUpdate: null,
installDate: new Date().toISOString(),
totalUsageTime: 0,
declineCount: 0
},
history: [],
metadata: {
version: CONFIG.version,
lastBackup: null,
migrationVersion: 1
}
// ❌ 已移除:remoteWhitelist 和 remoteWhitelistUpdatedAt 的默认值
};
return defaults[key] || {};
}
get(key, defaultValue = null) {
try {
return GM_getValue(this.prefix + key, defaultValue);
} catch (error) {
Utils.log(`读取存储失败: ${key}`, 'error');
return defaultValue;
}
}
set(key, value) {
try {
GM_setValue(this.prefix + key, value);
Utils.log(`存储成功: ${key}`);
return true;
} catch (error) {
Utils.log(`存储失败: ${key}`, 'error');
return false;
}
}
getSettings() {
return { ...CONFIG.defaultSettings, ...this.get('settings', {}) };
}
updateSetting(key, value) {
const settings = this.getSettings();
settings[key] = value;
this.set('settings', settings);
Utils.log(`设置更新: ${key} = ${value}`);
}
addHistory(record) {
const history = this.get('history', []);
const newRecord = {
id: Utils.generateId(),
timestamp: new Date().toISOString(),
...record
};
history.unshift(newRecord);
if (history.length > 200) { // 增加历史记录数量
history.splice(200);
}
this.set('history', history);
Utils.log('历史记录已保存');
return newRecord;
}
getHistory() {
return this.get('history', []);
}
clearHistory() {
this.set('history', []);
Utils.log('历史记录已清空');
}
updateStats(key, value = 1) {
const stats = this.get('stats', this.getDefaultValue('stats'));
stats[key] = (stats[key] || 0) + value;
stats.lastUpdate = new Date().toISOString();
this.set('stats', stats);
Utils.log(`统计更新: ${key} +${value}`);
}
getStats() {
return this.get('stats', this.getDefaultValue('stats'));
}
exportAllData() {
const data = {
settings: this.getSettings(),
stats: this.getStats(),
history: this.getHistory(),
metadata: {
version: CONFIG.version,
exportDate: new Date().toISOString(),
dataSize: this.calculateDataSize()
}
};
return data;
}
importAllData(data) {
try {
if (data.settings) this.set('settings', data.settings);
if (data.stats) this.set('stats', data.stats);
if (data.history) this.set('history', data.history);
Utils.log('数据导入成功');
return true;
} catch (error) {
Utils.log('数据导入失败: ' + error.message, 'error');
return false;
}
}
calculateDataSize() {
let totalSize = 0;
// ❌ 已移除:'remoteWhitelist', 'remoteWhitelistUpdatedAt' 的计算
['settings', 'stats', 'history', 'metadata'].forEach(key => {
const data = this.get(key);
if (data) {
totalSize += JSON.stringify(data).length;
}
});
return totalSize;
}
}
// ================== 页面信息提取 ==================
class PageInfo {
constructor() {
this.extract();
}
extract() {
try {
const userEl = document.querySelector('h1.text-2xl');
const userText = userEl ? userEl.textContent : '';
const userMatch = userText.match(/你好,\s*$([^)]+)$\s*(\d+)级用户/);
const systemEl = this.findTextElement('系统:');
const system = systemEl ? systemEl.textContent.replace('系统:', '').trim() : '未知系统';
// ✅ 正确从同一 <p> 内部取到 <a>
const websiteEl = this.findTextElement('网站:');
let website = '未知网站';
let websiteUrl = '';
if (websiteEl) {
const link = websiteEl.querySelector('a');
if (link) {
website = (link.textContent || '').trim();
websiteUrl = link.getAttribute('href') || '';
} else {
website = websiteEl.textContent.replace('网站:', '').trim();
}
}
// ✅ 归一化为纯域名(不带 https:// 且无末尾 /)
const websiteHost = Utils.normalizeHost(websiteUrl || website);
const descEl = this.findTextElement('描述:');
const description = descEl ? descEl.textContent.replace('描述:', '').trim() : '无描述';
this.info = {
user: {
name: userMatch ? userMatch[1] : '未知用户',
level: userMatch ? parseInt(userMatch[2]) : 0
},
system,
website,
websiteUrl,
description,
extractTime: new Date().toISOString(),
pageType: this.getPageType(),
url: window.location.href
};
Utils.log('页面信息提取完成');
} catch (error) {
Utils.log('页面信息提取失败', 'error');
this.info = {
user: { name: '未知用户', level: 0 },
system: '未知系统',
website: '未知网站',
websiteUrl: '',
websiteHost,
description: '无描述',
extractTime: new Date().toISOString(),
pageType: this.getPageType(),
url: window.location.href
};
}
}
getPageType() {
const path = window.location.pathname;
if (path.includes('/oauth2/approve')) return 'oauth-approve';
if (path.includes('/oauth2/decline')) return 'oauth-decline';
if (path.includes('/oauth2/')) return 'oauth-other';
return 'main';
}
findTextElement(text) {
const elements = document.querySelectorAll('strong');
for (const el of elements) {
if (el.textContent.includes(text)) {
return el.parentElement;
}
}
return null;
}
get() {
return this.info;
}
}
// ================== 点击跟踪管理器 ==================
class ClickTracker {
constructor(storage, settings) {
this.storage = storage;
this.settings = settings;
this.hasTrackedManualClick = false;
this.pageInfo = new PageInfo();
Utils.log('点击跟踪管理器初始化');
this.init();
}
async init() {
await this.waitForButtons();
this.addManualClickListeners();
}
async waitForButtons() {
return new Promise((resolve) => {
const checkButtons = () => {
// const approveBtn = document.querySelector(CONFIG.selectors.approveButton); // ❌ 已移除:自动点击相关按钮检查
const declineBtn = document.querySelector(CONFIG.selectors.declineButton);
if (/* approveBtn || */ declineBtn) { // ❌ 已移除:approveBtn 检查
Utils.log('找到授权按钮,准备添加监听器');
resolve();
} else {
setTimeout(checkButtons, 100);
}
};
checkButtons();
});
}
addManualClickListeners() {
// const approveBtn = document.querySelector(CONFIG.selectors.approveButton); // ❌ 已移除:自动点击相关按钮监听
// if (approveBtn) {
// approveBtn.addEventListener('click', (e) => {
// Utils.log('检测到手动点击授权按钮');
// this.recordManualClick('手动授权', 'approve');
// });
// }
const declineBtn = document.querySelector(CONFIG.selectors.declineButton);
if (declineBtn) {
declineBtn.addEventListener('click', (e) => {
Utils.log('检测到手动点击拒绝按钮');
this.recordManualClick('手动拒绝', 'decline');
});
}
}
recordManualClick(action, type) {
if (this.hasTrackedManualClick) {
Utils.log('已记录过手动点击,跳过');
return;
}
this.hasTrackedManualClick = true;
if (this.settings.saveLoginHistory) {
const pageInfo = this.pageInfo.get();
this.storage.addHistory({
action: action,
system: pageInfo.system,
website: pageInfo.website,
description: pageInfo.description,
user: pageInfo.user,
clickType: 'manual',
buttonType: type,
pageType: pageInfo.pageType,
url: pageInfo.url
});
Utils.log(`手动点击历史已记录: ${action}`);
}
this.storage.updateStats('manualClicks');
this.storage.updateStats('totalLogins');
if (type === 'decline') {
this.storage.updateStats('declineCount');
}
Utils.log(`手动点击统计已更新: ${action}`);
if (this.settings.showNotifications) {
this.showNotification(`${action}已记录`);
}
}
showNotification(message) {
if (typeof GM_notification === 'function') {
GM_notification({
title: '🏆 OAuth助手',
text: message,
timeout: this.settings.notificationDuration
});
}
}
updateSettings(settings) {
this.settings = settings;
}
}
// ================== 自动点击管理器 ==================
// ❌ 已移除:整个 AutoClickManager 类
/*
class AutoClickManager {
constructor(storage, settings) {
// ... 原有代码 ...
}
init() {
// ... 原有代码 ...
}
async attemptAutoClick() {
// ... 原有代码 ...
}
showNotification(message) {
// ... 原有代码 ...
}
updateSettings(settings) {
// ... 原有代码 ...
}
}
*/
// ================== UI管理器 ==================
class UIManager {
constructor(storage) {
this.storage = storage;
this.settings = storage.getSettings();
this.isVisible = false;
this.currentTheme = this.settings.theme;
this.currentUITheme = this.settings.uiTheme || 'minimal-white';
this.init();
}
init() {
this.addStyles();
this.createUI();
this.bindEvents();
this.applyTheme();
this.applyUITheme();
Utils.log('UI管理器初始化完成');
}
addStyles() {
const isOAuthPage = this.isOAuthPage();
const enableStyling = this.settings.enablePageStyling;
const uiTheme = CONFIG.uiThemes[this.currentUITheme];
let css = `
/* OAuth助手基础样式 */
.oauth-helper {
position: fixed;
${this.getPositionStyles()}
z-index: 10000;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}
.oauth-trigger {
width: 48px;
height: 48px;
background: ${uiTheme.colors.triggerBg};
border: 2px solid ${uiTheme.colors.panelBorder};
border-radius: 24px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
transition: all 0.3s ease;
color: ${uiTheme.colors.text};
font-size: 20px;
${this.currentUITheme === 'rainbow-fancy' ? 'animation: rainbow-rotate 4s ease-in-out infinite;' : ''}
}
.oauth-trigger:hover {
transform: translateY(-2px) scale(1.05);
box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.2);
${this.currentUITheme === 'rainbow-fancy' ? 'filter: brightness(1.1);' : ''}
}
.oauth-trigger.active {
transform: translateY(-1px) scale(1.02);
box-shadow: 0 8px 12px -2px rgba(0, 0, 0, 0.15);
}
.oauth-panel {
position: absolute;
${this.getPanelPositionStyles()}
width: 400px;
background: ${uiTheme.colors.panelBg};
border: 2px solid ${uiTheme.colors.panelBorder};
border-radius: 16px;
box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.25);
opacity: 0;
visibility: hidden;
transform: translateY(-12px) scale(0.95);
transition: all 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
overflow: hidden;
max-height: 80vh;
backdrop-filter: blur(10px);
${this.currentUITheme === 'rainbow-fancy' ? 'animation: rainbow-bg 6s ease-in-out infinite; background-size: 400% 400%;' : ''}
}
.oauth-panel.show {
opacity: 1;
visibility: visible;
transform: translateY(0) scale(1);
}
.oauth-header {
padding: 20px 24px;
background: ${this.currentUITheme === 'minimal-white' ? '#fafafa' : 'rgba(255,255,255,0.1)'};
border-bottom: 1px solid ${uiTheme.colors.panelBorder};
backdrop-filter: blur(5px);
}
.oauth-title {
font-size: 18px;
font-weight: 700;
color: ${uiTheme.colors.text};
margin: 0;
${this.currentUITheme === 'rainbow-fancy' ? 'background: linear-gradient(-45deg, #ee7752, #e73c7e, #23a6d5, #23d5ab); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent; animation: rainbow-text 3s ease-in-out infinite;' : ''}
}
.oauth-version {
font-size: 11px;
color: ${uiTheme.colors.textMuted};
margin-top: 4px;
font-weight: 500;
}
.oauth-content {
padding: 0;
max-height: calc(80vh - 100px);
overflow-y: auto;
background: ${this.currentUITheme === 'minimal-white' ? 'transparent' : 'rgba(255,255,255,0.05)'};
}
.oauth-content::-webkit-scrollbar {
width: 6px;
}
.oauth-content::-webkit-scrollbar-track {
background: transparent;
}
.oauth-content::-webkit-scrollbar-thumb {
background: ${uiTheme.colors.textMuted};
border-radius: 3px;
opacity: 0.5;
}
.oauth-section {
padding: 18px 24px;
border-bottom: 1px solid ${uiTheme.colors.panelBorder};
backdrop-filter: blur(2px);
}
.oauth-section:last-child {
border-bottom: none;
}
.oauth-section-title {
font-size: 14px;
font-weight: 700;
color: ${uiTheme.colors.text};
margin-bottom: 16px;
display: flex;
align-items: center;
gap: 10px;
${this.currentUITheme === 'rainbow-fancy' ? 'text-shadow: 0 0 10px rgba(255,255,255,0.5);' : ''}
}
.oauth-switch-item {
display: flex;
align-items: center;
justify-content: space-between;
padding: 14px 16px;
background: ${this.currentUITheme === 'minimal-white' ? '#f9fafb' : 'rgba(255,255,255,0.1)'};
border-radius: 12px;
margin-bottom: 10px;
transition: all 0.3s ease;
backdrop-filter: blur(5px);
${this.currentUITheme === 'rainbow-fancy' ? 'border: 1px solid rgba(255,255,255,0.2);' : ''}
}
.oauth-switch-item:hover {
background: ${this.currentUITheme === 'minimal-white' ? '#f3f4f6' : 'rgba(255,255,255,0.15)'};
transform: translateY(-1px);
${this.currentUITheme === 'rainbow-fancy' ? 'box-shadow: 0 4px 15px rgba(0,0,0,0.1);' : ''}
}
.oauth-switch-info {
flex: 1;
}
.oauth-switch-label {
font-size: 14px;
color: ${uiTheme.colors.text};
font-weight: 600;
margin-bottom: 3px;
}
.oauth-switch-desc {
font-size: 12px;
color: ${uiTheme.colors.textMuted};
line-height: 1.4;
}
.oauth-switch {
position: relative;
width: 44px;
height: 24px;
background: ${this.currentUITheme === 'minimal-white' ? '#e5e7eb' : 'rgba(255,255,255,0.2)'};
border-radius: 12px;
cursor: pointer;
transition: all 0.3s ease;
flex-shrink: 0;
}
.oauth-switch.active {
background: ${uiTheme.colors.accent};
${this.currentUITheme === 'rainbow-fancy' ? 'box-shadow: 0 0 20px rgba(255,107,107,0.6);' : ''}
}
.oauth-switch-knob {
position: absolute;
top: 2px;
left: 2px;
width: 20px;
height: 20px;
background: white;
border-radius: 50%;
transition: all 0.3s ease;
box-shadow: 0 2px 6px rgba(0, 0, 0, 0.2);
}
.oauth-switch.active .oauth-switch-knob {
transform: translateX(20px);
${this.currentUITheme === 'rainbow-fancy' ? 'box-shadow: 0 0 15px rgba(255,255,255,0.8);' : ''}
}
.oauth-btn {
background: ${this.currentUITheme === 'minimal-white' ? 'white' : 'rgba(255,255,255,0.1)'};
border: 1px solid ${uiTheme.colors.panelBorder};
color: ${uiTheme.colors.text};
font-size: 12px;
padding: 8px 14px;
border-radius: 8px;
cursor: pointer;
transition: all 0.3s ease;
font-weight: 600;
margin-right: 8px;
margin-bottom: 6px;
backdrop-filter: blur(5px);
display: inline-block;
}
.oauth-btn:hover {
background: ${this.currentUITheme === 'minimal-white' ? '#f3f4f6' : 'rgba(255,255,255,0.2)'};
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
}
.oauth-btn.primary {
background: ${uiTheme.colors.accent};
color: white;
border-color: ${uiTheme.colors.accent};
${this.currentUITheme === 'rainbow-fancy' ? 'background: linear-gradient(45deg, #ff6b6b, #4ecdc4); border: none;' : ''}
}
.oauth-btn.primary:hover {
${this.currentUITheme === 'rainbow-fancy' ? 'filter: brightness(1.1); transform: translateY(-2px);' : 'filter: brightness(0.9);'}
}
.oauth-btn.danger {
border-color: #ef4444;
color: #ef4444;
}
.oauth-btn.danger:hover {
border-color: #dc2626;
color: #dc2626;
background: ${this.currentUITheme === 'minimal-white' ? '#fef2f2' : 'rgba(239,68,68,0.1)'};
}
.oauth-stat-card {
background: ${this.currentUITheme === 'minimal-white' ? '#f9fafb' : 'rgba(255,255,255,0.1)'};
border: 1px solid ${uiTheme.colors.panelBorder};
border-radius: 12px;
padding: 16px;
text-align: center;
margin-bottom: 10px;
transition: all 0.3s ease;
backdrop-filter: blur(5px);
${this.currentUITheme === 'rainbow-fancy' ? 'border: 1px solid rgba(255,255,255,0.2);' : ''}
}
.oauth-stat-card:hover {
transform: translateY(-2px);
${this.currentUITheme === 'rainbow-fancy' ? 'box-shadow: 0 8px 25px rgba(0,0,0,0.15);' : ''}
}
.oauth-stat-value {
font-size: 24px;
font-weight: 800;
color: ${uiTheme.colors.text};
margin-bottom: 6px;
${this.currentUITheme === 'rainbow-fancy' ? 'background: linear-gradient(45deg, #ff6b6b, #4ecdc4); background-clip: text; -webkit-background-clip: text; -webkit-text-fill-color: transparent;' : ''}
}
.oauth-stat-label {
font-size: 11px;
color: ${uiTheme.colors.textMuted};
font-weight: 600;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.oauth-stat-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 10px;
margin-bottom: 16px;
}
/* 条形图样式 */
.oauth-chart-container {
background: ${this.currentUITheme === 'minimal-white' ? '#f9fafb' : 'rgba(255,255,255,0.1)'};
border: 1px solid ${uiTheme.colors.panelBorder};
border-radius: 12px;
padding: 16px;
margin-bottom: 16px;
backdrop-filter: blur(5px);
${this.currentUITheme === 'rainbow-fancy' ? 'border: 1px solid rgba(255,255,255,0.2);' : ''}
}
.oauth-chart-title {
font-size: 13px;
font-weight: 600;
color: ${uiTheme.colors.text};
margin-bottom: 12px;
text-align: center;
display: flex;
align-items: center;
justify-content: center;
gap: 6px;
}
.oauth-chart-bars {
display: flex;
align-items: end;
gap: 6px;
height: 100px;
justify-content: space-between;
margin-bottom: 4px;
}
.oauth-chart-bar-container {
display: flex;
flex-direction: column;
align-items: center;
flex: 1;
min-width: 0;
}
.oauth-chart-bar-wrapper {
position: relative;
display: flex;
align-items: end;
width: 100%;
margin-bottom: 8px;
}
.oauth-chart-bar {
width: 100%;
background: ${uiTheme.colors.accent};
border-radius: 4px 4px 0 0;
position: relative;
transition: all 0.3s ease;
min-height: 4px;
cursor: pointer;
${this.currentUITheme === 'rainbow-fancy' ? 'background: linear-gradient(45deg, #ff6b6b, #4ecdc4); box-shadow: 0 2px 8px rgba(255,107,107,0.3);' : ''}
}
.oauth-chart-bar:hover {
${this.currentUITheme === 'rainbow-fancy' ? 'filter: brightness(1.1); box-shadow: 0 4px 12px rgba(255,107,107,0.4);' : 'filter: brightness(0.9);'}
transform: translateY(-1px);
}
.oauth-chart-value {
position: absolute;
top: -20px;
left: 50%;
transform: translateX(-50%);
font-size: 10px;
font-weight: 600;
color: ${uiTheme.colors.text};
background: ${this.currentUITheme === 'minimal-white' ? 'rgba(255,255,255,0.9)' : 'rgba(0,0,0,0.7)'};
padding: 2px 6px;
border-radius: 4px;
white-space: nowrap;
opacity: 0;
transition: opacity 0.3s ease;
}
.oauth-chart-bar:hover .oauth-chart-value {
opacity: 1;
}
.oauth-chart-label {
font-size: 10px;
color: ${uiTheme.colors.textMuted};
font-weight: 500;
text-align: center;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}
.oauth-chart-empty {
text-align: center;
color: ${uiTheme.colors.textMuted};
font-size: 12px;
padding: 40px 20px;
font-style: italic;
}
.oauth-history-item {
padding: 16px;
border-bottom: 1px solid ${uiTheme.colors.panelBorder};
font-size: 13px;