-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathresource-path-generator.html
More file actions
736 lines (634 loc) · 23.3 KB
/
resource-path-generator.html
File metadata and controls
736 lines (634 loc) · 23.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
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ID/Path Toolkit</title>
<!-- 引入 Google Fonts -->
<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=M+PLUS+1p:wght@400;500;700&family=Rubik:wght@400;500;700&display=swap" rel="stylesheet">
<style>
* {
-webkit-tap-highlight-color: transparent;
}
:root {
/* 定义核心变量 */
--md-sys-color-primary: #76FF33;
--md-sys-color-on-primary: #001926;
--md-sys-color-surface: #001926;
--md-sys-color-surface-container: #0d2b3d;
--md-sys-color-on-surface: #BFD5FF;
--md-sys-color-outline: #BFD5FF;
--md-sys-color-error: #ffb4ab;
/* 圆角与间距 */
--radius-l: 24px;
--radius-m: 12px;
--radius-s: 4px;
--radius-pill: 50px;
}
body {
background-color: var(--md-sys-color-surface);
color: var(--md-sys-color-on-surface);
font-family: 'M PLUS 1p', sans-serif;
margin: 0;
padding: 0;
line-height: 1.6;
display: flex;
justify-content: center;
min-height: 100vh;
}
/* 字体层级定义 */
h1, h2, h3, h4, .label-text {
font-family: 'Rubik', sans-serif;
}
.container {
width: 100%;
max-width: 900px;
padding: 40px 20px;
box-sizing: border-box;
}
/* 标题样式 */
h1 {
text-align: center;
color: var(--md-sys-color-primary);
font-size: 2.5rem;
margin-bottom: 40px;
font-weight: 700;
letter-spacing: -0.5px;
}
h2 {
color: var(--md-sys-color-on-surface);
font-size: 1.5rem;
margin-top: 0;
margin-bottom: 20px;
border-bottom: 1px solid rgba(191, 213, 255, 0.2);
padding-bottom: 10px;
}
h3 {
color: var(--md-sys-color-primary);
font-size: 1.1rem;
margin-top: 30px;
margin-bottom: 15px;
font-weight: 500;
}
/* 卡片容器 (M3 Surface) */
.card {
background-color: var(--md-sys-color-surface-container);
border-radius: var(--radius-l);
padding: 30px;
margin-bottom: 30px;
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.4);
}
/* 输入框组 */
.input-group {
margin-bottom: 20px;
display: flex;
flex-direction: column;
}
label {
font-size: 0.9rem;
color: var(--md-sys-color-on-surface);
margin-bottom: 8px;
font-weight: 500;
opacity: 0.9;
}
/* M3 风格输入框 */
input[type="text"] {
background-color: transparent;
border: 1px solid rgba(191, 213, 255, 0.4);
border-radius: var(--radius-s);
color: var(--md-sys-color-on-surface);
padding: 12px 16px;
font-family: 'M PLUS 1p', monospace;
font-size: 1rem;
transition: all 0.2s ease;
width: 100%;
box-sizing: border-box;
}
input[type="text"]:focus {
border-color: var(--md-sys-color-primary);
outline: none;
box-shadow: 0 0 0 1px var(--md-sys-color-primary);
}
input[type="text"]::placeholder {
color: rgba(191, 213, 255, 0.3);
font-family: 'M PLUS 1p', sans-serif;
}
/* 按钮区域 */
.action-bar {
display: flex;
gap: 15px;
flex-wrap: wrap;
margin-top: 20px;
}
/* M3 风格按钮 */
button {
font-family: 'Rubik', sans-serif;
font-weight: 500;
font-size: 0.95rem;
padding: 12px 24px;
border-radius: var(--radius-pill);
cursor: pointer;
transition: transform 0.1s, box-shadow 0.2s, background-color 0.2s;
border: none;
display: inline-flex;
align-items: center;
justify-content: center;
}
/* 主要按钮 (Primary) */
button.primary-btn {
background-color: var(--md-sys-color-primary);
color: var(--md-sys-color-on-primary);
}
button.primary-btn:hover {
box-shadow: 0 4px 12px rgba(118, 255, 51, 0.3);
transform: translateY(-1px);
}
/* 次要按钮 (Secondary/Tonal) */
button.secondary-btn {
background-color: var(--md-sys-color-on-surface);
color: var(--md-sys-color-surface);
}
button.secondary-btn:hover {
background-color: #dbeaff;
box-shadow: 0 4px 12px rgba(191, 213, 255, 0.3);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
/* 结果显示框 */
.result-box {
margin-top: 20px;
font-family: 'M PLUS 1p', monospace;
background-color: rgba(0, 0, 0, 0.3);
border-left: 4px solid var(--md-sys-color-primary);
padding: 15px;
border-radius: 0 var(--radius-m) var(--radius-m) 0;
min-height: 24px;
white-space: pre-wrap;
word-break: break-all;
color: var(--md-sys-color-on-surface);
display: none; /* 默认隐藏,有内容时JS显示 */
}
/* 错误信息 */
.error {
color: var(--md-sys-color-error);
font-weight: bold;
display: block;
margin-top: 5px;
}
/* 说明盒子 */
.explanation-box {
margin-top: 25px;
background-color: rgba(191, 213, 255, 0.05);
padding: 20px;
border-radius: var(--radius-m);
border: 1px solid rgba(191, 213, 255, 0.1);
}
.explanation-box ul {
margin: 0;
padding-left: 20px;
list-style-type: none;
}
.explanation-box li {
margin-bottom: 12px;
padding-left: 10px;
border-left: 2px solid rgba(191, 213, 255, 0.3);
}
.explanation-box strong {
color: var(--md-sys-color-primary);
}
code {
background-color: rgba(0, 0, 0, 0.3);
padding: 2px 6px;
border-radius: 4px;
font-family: 'M PLUS 1p', monospace;
color: #fff;
}
.full-range {
color: var(--md-sys-color-primary);
font-style: italic;
opacity: 0.8;
font-size: 0.9em;
}
/* 响应式调整 */
@media (max-width: 600px) {
.container { padding: 20px 10px; }
.card { padding: 20px; }
button { width: 100%; margin-bottom: 10px; }
.action-bar { flex-direction: column; gap: 0; }
}
</style>
</head>
<body>
<div class="container">
<h1 data-i18n="mainTitle">ID/路径转换与分析工具集</h1>
<!-- ==================================================================== -->
<!-- 工具一 -->
<!-- ==================================================================== -->
<div class="card">
<h2 data-i18n="tool1Title">工具一:ResourceURL 路径 (ID + Version)</h2>
<h3 data-i18n="genPath5">路径生成器 (5 级)</h3>
<div class="input-group">
<label for="inputId_v" data-i18n="labelId">ID (Long)</label>
<input type="text" id="inputId_v" data-placeholder="phLong">
</div>
<div class="input-group">
<label for="inputVersion_v" data-i18n="labelVer">Version (Long)</label>
<input type="text" id="inputVersion_v" data-placeholder="phLongVer">
</div>
<div class="action-bar">
<button class="primary-btn" onclick="generatePath_v()" data-i18n="btnGen">生成路径</button>
</div>
<div id="resultGenerate_v" class="result-box"></div>
<h3 data-i18n="parsePath5">路径解析器 (5 级)</h3>
<div class="input-group">
<label for="inputPath_v" data-i18n="labelPath5">5 级路径字符串</label>
<input type="text" id="inputPath_v" data-placeholder="phPath5">
</div>
<div class="action-bar">
<button class="primary-btn" onclick="parsePath_v()" data-i18n="btnParse">解析路径</button>
</div>
<div id="resultParse_v" class="result-box"></div>
</div>
<!-- ==================================================================== -->
<!-- 工具二 -->
<!-- ==================================================================== -->
<div class="card">
<h2 data-i18n="tool2Title">工具二:4 级 ID 路径与范围分析</h2>
<h3 data-i18n="genIdPath4">ID 到 4 级路径生成器</h3>
<div class="input-group">
<label for="inputId1_4" data-i18n="labelId1">ID 1 (范围起点)</label>
<input type="text" id="inputId1_4" data-placeholder="phLong">
</div>
<div class="input-group">
<label for="inputId2_4" data-i18n="labelId2">ID 2 (范围终点)</label>
<input type="text" id="inputId2_4" data-placeholder="phLongOpt">
</div>
<div class="action-bar">
<button class="primary-btn" onclick="generatePaths_4()" data-i18n="btnGenForId">为 ID 生成路径</button>
<button class="secondary-btn" onclick="analyzeRange_4()" data-i18n="btnAnalyze">分析范围路径可能</button>
</div>
<div id="resultGenerate_4" class="result-box"></div>
<h3 data-i18n="rangeResultTitle">范围路径可能性分析结果</h3>
<div id="rangeAnalysisResult" class="explanation-box" data-i18n="rangeInstruction">
请在上方输入两个 ID 作为范围,然后点击“分析范围路径可能”按钮。
</div>
<h3 data-i18n="parsePath4">4 级路径到 ID 解析器</h3>
<div class="input-group">
<label for="inputPath_4" data-i18n="labelPath4">4 级路径字符串</label>
<input type="text" id="inputPath_4" data-placeholder="phPath4">
</div>
<div class="action-bar">
<button class="primary-btn" onclick="parsePath_4()" data-i18n="btnParseId">解析 ID</button>
</div>
<div id="resultParse_4" class="result-box"></div>
</div>
</div>
<script>
// --- 国际化配置 (I18n) ---
const translations = {
zh: {
mainTitle: "ID/路径转换与分析工具集",
tool1Title: "工具一:ResourceURL 路径 (ID + Version)",
genPath5: "路径生成器 (5 级)",
labelId: "ID (Long)",
labelVer: "Version (Long)",
btnGen: "生成路径",
parsePath5: "路径解析器 (5 级)",
labelPath5: "5 级路径字符串",
btnParse: "解析路径",
tool2Title: "工具二:4 级 ID 路径与范围分析",
genIdPath4: "ID 到 4 级路径生成器",
labelId1: "ID 1 (范围起点)",
labelId2: "ID 2 (范围终点)",
btnGenForId: "为 ID 生成路径",
btnAnalyze: "分析范围路径可能",
rangeResultTitle: "范围路径可能性分析结果",
rangeInstruction: "请在上方输入两个 ID 作为范围,然后点击“分析范围路径可能”按钮。",
parsePath4: "4 级路径到 ID 解析器",
labelPath4: "4 级路径字符串",
btnParseId: "解析 ID",
// Placeholders
phLong: "请输入长整型数值",
phLongVer: "请输入长整型版本号",
phPath5: "请输入五级路径字符串 (以斜杠分隔)",
phLongOpt: "请输入第二个长整型 ID (可选)",
phPath4: "请输入四级路径字符串 (以斜杠分隔)",
// JS Dynamic Messages
errIdVerEmpty: "ID 和 Version 都不能为空!",
resGenPath: "生成的路径",
errGen: "生成错误",
errValidInt: "请确保输入的是有效的整数。",
errPathEmpty: "路径字符串不能为空!",
resParse: "解析结果",
errParse: "解析错误",
pathFor: "路径",
errId: "错误",
errOneId: "请至少输入一个 ID。",
rangeAnalysis: "范围分析",
rangeErrInput: "请输入两个 ID 以定义分析范围。",
rangePossible: "路径可能性",
rangeOf: "ID 范围",
level: "级", // Level
decRange: "十进制范围",
octRange: "八进制范围",
fullRange: "覆盖所有可能值",
to: "到"
},
en: {
mainTitle: "ID/Path Conversion & Analysis Toolkit",
tool1Title: "Tool 1: ResourceURL Path (ID + Version)",
genPath5: "Path Generator (Level 5)",
labelId: "ID (Long)",
labelVer: "Version (Long)",
btnGen: "Generate Path",
parsePath5: "Path Parser (Level 5)",
labelPath5: "Level 5 Path String",
btnParse: "Parse Path",
tool2Title: "Tool 2: Level 4 ID Path & Range Analysis",
genIdPath4: "ID to Level 4 Path Generator",
labelId1: "ID 1 (Start of Range)",
labelId2: "ID 2 (End of Range)",
btnGenForId: "Generate Path for ID",
btnAnalyze: "Analyze Range Possibilities",
rangeResultTitle: "Range Path Analysis Results",
rangeInstruction: "Please enter two IDs above to define a range, then click 'Analyze Range Possibilities'.",
parsePath4: "Level 4 Path to ID Parser",
labelPath4: "Level 4 Path String",
btnParseId: "Parse ID",
// Placeholders
phLong: "Enter long integer value",
phLongVer: "Enter long integer version",
phPath5: "Enter 5-level path string (slash separated)",
phLongOpt: "Enter second long ID (Optional)",
phPath4: "Enter 4-level path string (slash separated)",
// JS Dynamic Messages
errIdVerEmpty: "ID and Version cannot be empty!",
resGenPath: "Generated Path",
errGen: "Generation Error",
errValidInt: "Please ensure input is a valid integer.",
errPathEmpty: "Path string cannot be empty!",
resParse: "Parse Result",
errParse: "Parse Error",
pathFor: "Path",
errId: "Error",
errOneId: "Please enter at least one ID.",
rangeAnalysis: "Range Analysis",
rangeErrInput: "Please enter two IDs to define the analysis range.",
rangePossible: "Path Possibilities",
rangeOf: "ID Range",
level: "Level", // Level
decRange: "Decimal Range",
octRange: "Octal Range",
fullRange: "Covers full range",
to: "to"
}
};
// 语言检测
let currentLang = 'zh'; // 默认中文
const userLang = navigator.language || navigator.userLanguage;
if (!userLang.startsWith('zh')) {
currentLang = 'en';
document.documentElement.lang = 'en';
}
// 获取文本辅助函数
function t(key) {
return translations[currentLang][key] || key;
}
// 初始化页面文本
function initI18n() {
// 替换文本内容
document.querySelectorAll('[data-i18n]').forEach(el => {
const key = el.getAttribute('data-i18n');
if (translations[currentLang][key]) {
el.textContent = translations[currentLang][key];
}
});
// 替换 Placeholder
document.querySelectorAll('[data-placeholder]').forEach(el => {
const key = el.getAttribute('data-placeholder');
if (translations[currentLang][key]) {
el.placeholder = translations[currentLang][key];
}
});
}
// --- 通用核心函数 ---
function getHighInt(longValBigInt) {
return Number(longValBigInt >> 32n);
}
function getLowInt(longValBigInt) {
return Number(longValBigInt & 0xFFFFFFFFn);
}
// --- 工具一: ResourceURL (ID + Version) ---
function toPath_v(id, version) {
const idBigInt = BigInt(id);
const versionBigInt = BigInt(version);
const highId = getHighInt(idBigInt);
const lowId = getLowInt(idBigInt);
return [
highId.toString(8),
((lowId >>> 16) & 0xFFFF).toString(8),
((lowId >>> 8) & 0xFF).toString(8),
(lowId & 0xFF).toString(8),
versionBigInt.toString(8)
].join("/");
}
function fromPath_v(pathStr) {
if (!pathStr || typeof pathStr !== 'string') throw new Error("Input invalid.");
const parts = pathStr.split('/');
if (parts.length !== 5) throw new Error("Invalid format (needs 5 parts).");
const parsedOctalParts = parts.map((part, index) => {
const num = parseInt(part, 8);
if (isNaN(num)) throw new Error(`Invalid octal part: "${part}"`);
return num;
});
const highId_val = BigInt(parsedOctalParts[0]);
const lowId_p1_val = BigInt(parsedOctalParts[1]);
const lowId_p2_val = BigInt(parsedOctalParts[2]);
const lowId_p3_val = BigInt(parsedOctalParts[3]);
const reconstructedLowIdUnsigned = (lowId_p1_val << 16n) | (lowId_p2_val << 8n) | lowId_p3_val;
const id = (highId_val << 32n) | reconstructedLowIdUnsigned;
const version = BigInt(parsedOctalParts[4]);
return { id, version };
}
function generatePath_v() {
const idStr = document.getElementById('inputId_v').value.trim();
const versionStr = document.getElementById('inputVersion_v').value.trim();
const resultDiv = document.getElementById('resultGenerate_v');
resultDiv.style.display = 'block';
if (!idStr || !versionStr) {
resultDiv.innerHTML = `<span class="error">${t('errIdVerEmpty')}</span>`;
return;
}
try {
const generatedPath = toPath_v(idStr, versionStr);
resultDiv.innerHTML = `<strong>${t('resGenPath')}:</strong><br>${generatedPath}`;
document.getElementById('inputPath_v').value = generatedPath;
} catch (e) {
resultDiv.innerHTML = `<span class="error">${t('errGen')}: ${e.message} ${t('errValidInt')}</span>`;
}
}
function parsePath_v() {
const pathStr = document.getElementById('inputPath_v').value.trim();
const resultDiv = document.getElementById('resultParse_v');
resultDiv.style.display = 'block';
if (!pathStr) {
resultDiv.innerHTML = `<span class="error">${t('errPathEmpty')}</span>`;
return;
}
try {
const { id, version } = fromPath_v(pathStr);
resultDiv.innerHTML = `<strong>${t('resParse')}:</strong><br>ID = ${id.toString()}<br>Version = ${version.toString()}`;
document.getElementById('inputId_v').value = id.toString();
document.getElementById('inputVersion_v').value = version.toString();
} catch (e) {
resultDiv.innerHTML = `<span class="error">${t('errParse')}: ${e.message}</span>`;
}
}
// --- 工具二: 4级 ID 路径 ---
function toPath_4(id) {
const idBigInt = BigInt(id);
const highId = getHighInt(idBigInt);
const lowId = getLowInt(idBigInt);
return [
highId.toString(8),
((lowId >>> 16) & 0xFFFF).toString(8),
((lowId >>> 8) & 0xFF).toString(8),
(lowId & 0xFF).toString(8)
].join("/");
}
function fromPath_4(pathStr) {
if (!pathStr || typeof pathStr !== 'string') throw new Error("Input invalid.");
const parts = pathStr.split('/');
if (parts.length !== 4) throw new Error("Invalid format (needs 4 parts).");
const parsedOctalParts = parts.map((part, index) => {
const num = parseInt(part, 8);
if (isNaN(num)) throw new Error(`Invalid octal part: "${part}"`);
return num;
});
const highId_val = BigInt(parsedOctalParts[0]);
const lowId_p1_val = BigInt(parsedOctalParts[1]);
const lowId_p2_val = BigInt(parsedOctalParts[2]);
const lowId_p3_val = BigInt(parsedOctalParts[3]);
const reconstructedLowIdUnsigned = (lowId_p1_val << 16n) | (lowId_p2_val << 8n) | lowId_p3_val;
const id = (highId_val << 32n) | reconstructedLowIdUnsigned;
return { id };
}
function generatePaths_4() {
const idStr1 = document.getElementById('inputId1_4').value.trim();
const idStr2 = document.getElementById('inputId2_4').value.trim();
const resultDiv = document.getElementById('resultGenerate_4');
resultDiv.innerHTML = '';
resultDiv.style.display = 'block';
let outputHtml = '';
let generatedPathForParser = '';
if (idStr1) {
try {
const path1 = toPath_4(idStr1);
outputHtml += `<div><strong>ID 1 (${idStr1}) ${t('pathFor')}:</strong><br>${path1}</div>`;
generatedPathForParser = path1;
} catch (e) {
outputHtml += `<div><strong>ID 1 ${t('errId')}:</strong> <span class="error">${e.message}</span></div>`;
}
}
if (idStr2) {
if (idStr1) outputHtml += '<br>';
try {
const path2 = toPath_4(idStr2);
outputHtml += `<div><strong>ID 2 (${idStr2}) ${t('pathFor')}:</strong><br>${path2}</div>`;
if (!generatedPathForParser) generatedPathForParser = path2;
} catch (e) {
outputHtml += `<div><strong>ID 2 ${t('errId')}:</strong> <span class="error">${e.message}</span></div>`;
}
}
if (!idStr1 && !idStr2) {
outputHtml = `<span class="error">${t('errOneId')}</span>`;
}
resultDiv.innerHTML = outputHtml;
if(generatedPathForParser) {
document.getElementById('inputPath_4').value = generatedPathForParser;
}
}
function parsePath_4() {
const pathStr = document.getElementById('inputPath_4').value.trim();
const resultDiv = document.getElementById('resultParse_4');
resultDiv.style.display = 'block';
if (!pathStr) {
resultDiv.innerHTML = `<span class="error">${t('errPathEmpty')}</span>`;
return;
}
try {
const { id } = fromPath_4(pathStr);
resultDiv.innerHTML = `<strong>${t('resParse')}:</strong><br>ID = ${id.toString()}`;
document.getElementById('inputId1_4').value = id.toString();
document.getElementById('inputId2_4').value = '';
} catch (e) {
resultDiv.innerHTML = `<span class="error">${t('errParse')}: ${e.message}</span>`;
}
}
function analyzeRange_4() {
const idStr1 = document.getElementById('inputId1_4').value.trim();
const idStr2 = document.getElementById('inputId2_4').value.trim();
const resultDiv = document.getElementById('rangeAnalysisResult');
if (!idStr1 || !idStr2) {
resultDiv.innerHTML = `<h3>${t('rangeAnalysis')}</h3><span class="error">${t('rangeErrInput')}</span>`;
return;
}
try {
const id1 = BigInt(idStr1);
const id2 = BigInt(idStr2);
const startId = id1 < id2 ? id1 : id2;
const endId = id1 < id2 ? id2 : id1;
let html = `<h3>${t('rangeOf')} [${startId}, ${endId}] ${t('rangePossible')}:</h3><ul>`;
const l1_min = startId >> 32n;
const l1_max = endId >> 32n;
html += formatRangeResult_4(`${t('level')} 1`, l1_min, l1_max, (l1_max - l1_min) > 1000);
if (l1_min < l1_max) {
html += formatRangeResult_4(`${t('level')} 2`, 0, 65535, true);
html += formatRangeResult_4(`${t('level')} 3`, 0, 255, true);
html += formatRangeResult_4(`${t('level')} 4`, 0, 255, true);
} else {
const low_start = Number(startId & 0xFFFFFFFFn);
const low_end = Number(endId & 0xFFFFFFFFn);
const l2_min = (low_start >>> 16) & 0xFFFF;
const l2_max = (low_end >>> 16) & 0xFFFF;
html += formatRangeResult_4(`${t('level')} 2`, l2_min, l2_max, l2_min === 0 && l2_max === 65535);
if (l2_min < l2_max) {
html += formatRangeResult_4(`${t('level')} 3`, 0, 255, true);
} else {
const l3_min = (low_start >>> 8) & 0xFF;
const l3_max = (low_end >>> 8) & 0xFF;
html += formatRangeResult_4(`${t('level')} 3`, l3_min, l3_max);
}
if ((low_start >>> 8) < (low_end >>> 8)) {
html += formatRangeResult_4(`${t('level')} 4`, 0, 255, true);
} else {
const l4_min = low_start & 0xFF;
const l4_max = low_end & 0xFF;
html += formatRangeResult_4(`${t('level')} 4`, l4_min, l4_max);
}
}
html += '</ul>';
resultDiv.innerHTML = html;
} catch (e) {
resultDiv.innerHTML = `<h3>${t('rangeAnalysis')}</h3><span class="error">${t('errParse')}: ${e.message}</span>`;
}
}
function formatRangeResult_4(levelName, minVal, maxVal, isFullRange = false) {
let fullRangeText = isFullRange ? ` <span class="full-range">(${t('fullRange')})</span>` : "";
return `<li>
<strong>${levelName}:</strong>
<div>${t('decRange')}: <code>${minVal.toString()}</code> ${t('to')} <code>${maxVal.toString()}</code>${fullRangeText}</div>
<div>${t('octRange')}: <code>${BigInt(minVal).toString(8)}</code> ${t('to')} <code>${BigInt(maxVal).toString(8)}</code></div>
</li>`;
}
// 页面加载时执行翻译
window.onload = function() {
initI18n();
}
</script>
</body>
</html>