forked from xingguangcuican6666/ABK
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
87 lines (76 loc) · 2.48 KB
/
Copy pathmain.js
File metadata and controls
87 lines (76 loc) · 2.48 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
/**
* 入口模块:初始化所有子模块,加载并渲染内核数据
*/
// 导入 SCSS 样式(webpack 会处理打包)
import '../scss/main.scss';
import { t } from './i18n.js';
import { initI18n } from './i18n.js';
import { initTheme } from './theme.js';
import { initModal, hideModal } from './modal.js';
import { initAnnouncement, hideAnnounce } from './announcement.js';
import { initSearch } from './search.js';
import { initTimeConverter } from './time-converter.js';
import { initBackToTop } from './back-to-top.js';
import { showToast } from './toast.js';
import { copyText, fetchJsonFresh } from './utils.js';
import { DATA_FILES } from './config.js';
import { renderTabs, renderPanels, animateCounters, initRipple } from './render.js';
// 初始化各模块
initI18n();
initTheme();
initModal();
initSearch();
initTimeConverter();
initBackToTop();
// ESC 关闭所有弹窗
document.addEventListener('keydown', function (e) {
if (e.key === 'Escape') { hideModal(); hideAnnounce(); }
});
// 复制按钮全局事件委托(弹窗 + 时间转换器共用)
document.addEventListener('click', function (e) {
var btn = e.target.closest('.modal-copy');
if (!btn) return;
var text = btn.dataset.copy;
if (!text) return;
copyText(text).then(function () {
btn.textContent = t.copied;
btn.classList.add('copied');
showToast(t.tcToast);
setTimeout(function () {
btn.textContent = t.copy;
btn.classList.remove('copied');
}, 1500);
}).catch(function () {});
});
// 加载内核数据
async function loadData() {
var results = await Promise.allSettled(
DATA_FILES.map(function (f) {
return fetchJsonFresh('data/' + f.android + '/' + f.kernel + '.json');
})
);
var datasets = [];
for (var i = 0; i < results.length; i++) {
if (results[i].status === 'fulfilled') {
datasets.push({ meta: DATA_FILES[i], data: results[i].value });
}
}
if (datasets.length === 0) {
document.getElementById('content').innerHTML =
'<div class="error"><p>' + t.errorTitle + '</p><p style="margin-top:0.5rem;color:var(--text-muted)">' + t.errorHint + '</p></div>';
return;
}
renderTabs(datasets);
renderPanels(datasets);
initRipple();
// 激活第一个标签页并触发计数动画
var firstTab = document.querySelector('.tab');
if (firstTab) {
firstTab.click();
var firstPanel = document.querySelector('.tab-panel.active');
if (firstPanel) animateCounters(firstPanel);
}
}
// 启动
initAnnouncement();
loadData();