-
Notifications
You must be signed in to change notification settings - Fork 10
/
test.html
137 lines (127 loc) · 3.93 KB
/
test.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Testseite</title>
<style>
table {
border-collapse: collapse;
}
th,td {
border: 1px solid #000;
}
</style>
<script type="module">
const languagepacks = [
'wc_langPacks/wc_langPack_CH_BERN.js',
'wc_langPacks/wc_langPack_DE_SWG.js',
'wc_langPacks/wc_langPack_DE.js',
'wc_langPacks/wc_langPack_EN.js',
'wc_langPacks/wc_langPack_NL.js',
'wc_langPacks/wc_langPack_NL-min.js',
];
function renderTable(langs, round) {
let res = '';
for (let h = 0; h < 24; h++) {
for (let m = 0; m < 60; m++) {
res += `<tr><td>${h.toString().padStart(2, '0')}:${m
.toString()
.padStart(2, '0')}</td>`;
for (const lang of langs) {
const pack = languagePackOpjects.get(lang);
res += `<td>${pack.timeString(h, m, {round})}</td><td>${renderedTime(
pack,
h,
m,
round
)}</td>`;
}
res += '</tr>';
}
}
return res;
}
function renderedTime(pack, h, m, round) {
const timeString = pack.timeString(h, m, {round});
const lines = pack.letterSet.map((line) => line.join(''));
const renderedWords = timeString.split(' ');
let res = [];
let currentLine = lines.shift();
for (const renderedWord of renderedWords) {
while (!currentLine.includes(renderedWord) && lines.length > 0) {
currentLine = lines.shift();
}
let start = currentLine.indexOf(renderedWord);
if(start != -1) {
res.push(renderedWord);
currentLine = currentLine.slice(start + renderedWord.length + 1);
}
}
let rendered = res.join(" ");
if(rendered != timeString) {
rendered += "❌"
}
return rendered
}
async function main() {
for (const languagepack of languagepacks) {
await loadScript(languagepack);
}
const langs = [...languagePackOpjects.keys()];
const tableContent = `
<thead>
<tr>
<th rowspan=2>Time</th>
${langs.map((lang) => `<th colspan=2>${lang}</th>`).join('')}
</tr>
<tr>
${langs.map((lang) => `<th>Wanted</th><th>Rendered</th>`).join('')}
</tr>
</thead>
<tbody>
${renderTable(langs, false)}
</tbody>
<thead>
<tr>
<th rowspan=2>Rounded Time</th>
${langs.map((lang) => `<th colspan=2>${lang}</th>`).join('')}
</tr>
<tr>
${langs.map((lang) => `<th>Wanted</th><th>Rendered</th>`).join('')}
</tr>
</thead>
<tbody>
${renderTable(langs, true)}
</tbody>
`;
table.innerHTML = tableContent;
}
const languagePackOpjects = new Map();
const table = document.querySelector('table');
function wc_addLanguagePack(pack) {
let langCode = pack.langCode;
if (languagePackOpjects.has(langCode)) {
langCode += '-dup';
}
languagePackOpjects.set(langCode, pack);
}
window.wc_addLanguagePack = wc_addLanguagePack;
function loadScript(src) {
return new Promise((res, rej) => {
const script = document.createElement('script');
script.onload = res;
script.src = src;
document.head.appendChild(script);
});
}
main();
</script>
</head>
<body>
<h1>WordClock Test</h1>
<p>This page is for testing the output of a languagepack</p>
<table></table>
</body>
</html>