Repository navigation
Expand file tree
/
Copy pathindex.html
More file actions
323 lines (298 loc) · 12.3 KB
/
Copy pathindex.html
File metadata and controls
323 lines (298 loc) · 12.3 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
<!doctype html>
<html lang="en">
<head>
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<!-- 非阻塞加载:图标字体不阻挡首帧渲染(字体加载慢/失败时首帧不再白屏) -->
<link
href="https://fonts.googleapis.com/css2?family=Material+Symbols+Outlined:opsz,wght,FILL,GRAD@20..48,100..700,0..1,-50..200&display=swap"
rel="stylesheet"
media="print"
onload="this.media = 'all'"
/>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Colorify 7</title>
</head>
<body>
<div id="root"></div>
<!-- 启动兜底 -->
<script>
(function () {
var w = window;
var d = document;
var booted = false;
var panelShown = false;
var zh = (navigator.language || "").toLowerCase().indexOf("zh") === 0;
function t(zhText, enText) {
return zh ? zhText : enText;
}
function esc(value) {
return String(value == null ? "" : value)
.replace(/&/g, "&")
.replace(/</g, "<")
.replace(/>/g, ">");
}
function ua() {
return navigator.userAgent || "";
}
function chromeMajor() {
var m = ua().match(/Chrome\/(\d+)/);
return m ? parseInt(m[1], 10) : 0;
}
function isAndroid() {
return /Android/i.test(ua());
}
function isWebView() {
return /\bwv\b/i.test(ua());
}
function check(name, fn) {
try {
return { name: name, ok: !!fn() };
} catch (e) {
return { name: name, ok: false };
}
}
function features() {
return [
check("customElements", function () {
return w.customElements && w.customElements.define;
}),
check("Shadow DOM", function () {
return !!Element.prototype.attachShadow;
}),
check("adoptedStyleSheets", function () {
return "adoptedStyleSheets" in d;
}),
check("replaceAll", function () {
return typeof String.prototype.replaceAll === "function";
}),
check("ResizeObserver", function () {
return typeof w.ResizeObserver === "function";
}),
check("structuredClone", function () {
return typeof w.structuredClone === "function";
}),
check("Promise.allSettled", function () {
return typeof Promise.allSettled === "function";
}),
check("Object.fromEntries", function () {
return typeof Object.fromEntries === "function";
}),
];
}
function diagText(error) {
var lines = [];
lines.push("=== Colorify boot diagnostics ===");
lines.push("time: " + new Date().toISOString());
lines.push("url: " + w.location.href);
lines.push("language: " + (navigator.language || "?"));
lines.push("android: " + (isAndroid() ? "yes" : "no"));
lines.push("webview: " + (isWebView() ? "yes" : "no"));
lines.push("chrome: " + (chromeMajor() || "unknown"));
lines.push("tauri: " + (w.__TAURI_INTERNALS__ ? "yes" : "no"));
lines.push("ua: " + ua());
lines.push("features:");
var list = features();
for (var i = 0; i < list.length; i++) {
lines.push(" " + (list[i].ok ? "[ok] " : "[--] ") + list[i].name);
}
lines.push("error: " + (error ? error : "(none)"));
return lines.join("\n");
}
function style() {
if (d.getElementById("colorify-boot-style")) return;
var s = d.createElement("style");
s.id = "colorify-boot-style";
s.textContent = [
"#colorify-boot-loading{position:fixed;left:0;right:0;top:0;bottom:0;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:14px;background:#111318;color:#d0d3dc;font-family:system-ui,-apple-system,sans-serif;z-index:2147483646}",
"#colorify-boot-loading .c-spin{width:32px;height:32px;border:3px solid rgba(255,255,255,.15);border-top-color:#a8c7fa;border-radius:50%;animation:c-spin .8s linear infinite}",
"@keyframes c-spin{to{transform:rotate(360deg)}}",
"#colorify-boot-panel{position:fixed;left:0;right:0;top:0;bottom:0;overflow:auto;-webkit-overflow-scrolling:touch;background:#0d0f13;color:#e6e8ee;font-family:system-ui,-apple-system,sans-serif;z-index:2147483647;padding:24px 20px;box-sizing:border-box}",
"#colorify-boot-panel .c-title{font-size:18px;font-weight:600;margin:0 0 8px}",
"#colorify-boot-panel .c-intro{font-size:13px;line-height:1.6;color:#aab0bd;margin:0 0 16px;white-space:pre-wrap}",
"#colorify-boot-panel .c-label{font-size:12px;letter-spacing:.04em;color:#8e94a3;margin:0 0 6px}",
"#colorify-boot-panel pre{white-space:pre-wrap;word-break:break-word;background:#161a22;border:1px solid #242a36;border-radius:8px;padding:12px;font-size:12px;line-height:1.5;margin:0 0 16px;max-height:46vh;overflow:auto}",
"#colorify-boot-panel .c-actions{display:flex;flex-wrap:wrap;gap:8px}",
"#colorify-boot-panel button{appearance:none;border:1px solid #2c3342;background:#1b2029;color:#e6e8ee;border-radius:999px;padding:8px 16px;font-size:13px}",
].join("");
d.head.appendChild(s);
}
function showLoading() {
if (d.getElementById("colorify-boot-loading")) return;
style();
var el = d.createElement("div");
el.id = "colorify-boot-loading";
el.innerHTML =
'<div class="c-spin"></div><div>' +
esc(t("正在启动 Colorify…", "Starting Colorify…")) +
"</div>";
d.body.appendChild(el);
}
function hideLoading() {
var el = d.getElementById("colorify-boot-loading");
if (el && el.parentNode) el.parentNode.removeChild(el);
}
function showPanel(title, intro, error) {
if (panelShown) return;
panelShown = true;
hideLoading();
style();
var text = diagText(error);
var box = d.createElement("div");
box.id = "colorify-boot-panel";
box.innerHTML =
'<div class="c-title">' +
esc(title) +
"</div>" +
'<div class="c-intro">' +
esc(intro) +
"</div>" +
'<div class="c-label">' +
esc(t("诊断信息", "Diagnostics")) +
"</div>" +
'<pre id="colorify-diag-text">' +
esc(text) +
"</pre>" +
'<div class="c-actions">' +
'<button id="colorify-diag-copy">' +
esc(t("复制诊断信息", "Copy diagnostics")) +
"</button>" +
'<button id="colorify-diag-reload">' +
esc(t("重新加载", "Reload")) +
"</button>" +
'<button id="colorify-diag-hide">' +
esc(t("隐藏此面板", "Hide panel")) +
"</button>" +
"</div>";
d.body.appendChild(box);
d.getElementById("colorify-diag-copy").onclick = function () {
var value = diagText(error);
var button = d.getElementById("colorify-diag-copy");
function done() {
button.textContent = t("已复制", "Copied");
}
function fallback() {
try {
var pre = d.getElementById("colorify-diag-text");
var range = d.createRange();
range.selectNodeContents(pre);
var sel = w.getSelection();
sel.removeAllRanges();
sel.addRange(range);
d.execCommand("copy");
done();
} catch (e) {
/* ignore */
}
}
try {
if (navigator.clipboard && navigator.clipboard.writeText) {
navigator.clipboard.writeText(value).then(done, fallback);
} else {
fallback();
}
} catch (e) {
fallback();
}
};
d.getElementById("colorify-diag-reload").onclick = function () {
w.location.reload();
};
d.getElementById("colorify-diag-hide").onclick = function () {
if (box.parentNode) box.parentNode.removeChild(box);
};
}
w.__colorifyShowError = function (error) {
try {
var message = "";
if (error && (error.stack || error.message)) {
message = error.stack || error.message;
} else if (error) {
message = String(error);
}
showPanel(
t("Colorify 启动失败", "Colorify failed to start"),
t(
"应用在启动过程中出错。请把下面的诊断信息发给开发者,或更新系统 WebView 后重试。",
"The app hit an error while starting. Please send the diagnostics below to the developer, or update the System WebView and try again.",
),
message,
);
} catch (e) {
/* ignore */
}
};
w.__colorifyBooted = function () {
booted = true;
hideLoading();
};
w.onerror = function (message, source, lineno, colno, error) {
w.__colorifyShowError(
error || message + " @" + source + ":" + lineno + ":" + colno,
);
return false;
};
w.addEventListener("unhandledrejection", function (event) {
// 启动完成后的零散 Promise 拒绝不覆盖界面;启动阶段的失败才展示诊断
if (!booted) w.__colorifyShowError(event && event.reason);
});
// 手动触发诊断面板:?colorify-diag=1
if ((w.location.search || "").indexOf("colorify-diag=1") >= 0) {
showPanel(
t("诊断面板", "Diagnostics panel"),
t("这是手动触发的诊断信息。", "This panel was opened manually."),
null,
);
} else {
showLoading();
if (isAndroid()) {
var missing = [];
var list = features();
var critical = {
customElements: 1,
"Shadow DOM": 1,
adoptedStyleSheets: 1,
replaceAll: 1,
ResizeObserver: 1,
};
for (var i = 0; i < list.length; i++) {
if (critical[list[i].name] && !list[i].ok) {
missing.push(list[i].name);
}
}
var major = chromeMajor();
if (missing.length || (major > 0 && major < 85)) {
showPanel(
t("系统 WebView 版本过低", "System WebView is too old"),
t(
"当前系统 WebView 缺少 Colorify 需要的能力(" +
(missing.join("、") || "Chromium " + major) +
")。请更新「Android System WebView」或系统后重试。",
"The System WebView is missing features Colorify requires (" +
(missing.join(", ") || "Chromium " + major) +
'). Please update "Android System WebView" or your system and try again.',
),
null,
);
}
}
w.setTimeout(function () {
if (!booted && !panelShown) {
showPanel(
t("启动超时", "Startup timed out"),
t(
"应用在 15 秒内没有完成启动。请把下面的诊断信息发给开发者。",
"The app did not finish starting within 15 seconds. Please send the diagnostics below to the developer.",
),
null,
);
}
}, 15000);
}
})();
</script>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>