-
Notifications
You must be signed in to change notification settings - Fork 1
/
carplates.html
195 lines (169 loc) · 5.15 KB
/
carplates.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
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
<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<style>
html,
body,
* {
font-family: monospace;
font-size: 1.1rem;
}
#result {
height: 90%;
display: flex;
flex-direction: column;
flex-wrap: wrap;
list-style: none;
}
#result li {
margin-right: 10px;
cursor: pointer;
}
#result .c1 {
color: #0009;
}
#result .c2 {
color: #00f;
}
#result .c3 {
font-size: 0.6rem;
}
</style>
<script>
const codePool = [];
String.prototype.isNumber = function () {
return !isNaN(this);
/*
for (let c of Array.from(this)) {
const code = c.charCodeAt(0);
if (code < 48 || code > 57) return false;
}
return true;
*/
}
String.prototype.isAlphabet = function () {
for (let c of Array.from(this)) {
const code = c.charCodeAt(0);
if (code < 65 || (code > 90 && code < 97) || code > 122) return false;
}
return true;
}
function reload() {
const dateFrom = document.querySelector('#dateFrom').value;
console.log('dateFrom', dateFrom);
const excludes = document.querySelector('#excludes').value.split('').filter(c => c.trim().length > 0);
console.log('excludes', excludes);
let result = codePool.filter(r => r.date.slice(0, 4) >= dateFrom)
.map(r => generateCode(r.range).map(c => ({ code: c, date: r.date.slice(0, 4) })))
.flat()
.filter(c => {
const arr = c.code.slice(1).split('');
for (let i of arr) {
if (excludes.includes(i)) return false;
}
return true;
});
const pattern = document.querySelector('#pattern').value.split('');
console.log('pattern', pattern);
const wildcard = document.querySelector('#wildcard').value.split('');
console.log('wildcard', wildcard);
if (pattern && pattern.length == 5) {
// pattern
const zIndex = pattern.indexOf('Z') + 1;
const [a1, a2] = pattern.map((c, i) => c == 'A' ? i + 1 : null).filter(i => i != null);
const [b1, b2] = pattern.map((c, i) => c == 'B' ? i + 1 : null).filter(i => i != null);
console.log(zIndex, [a1, a2], [b1, b2]);
result = result.filter(c => c.code.charAt(zIndex).isAlphabet());
result = result.filter(c => c.code.charAt(a1) == c.code.charAt(a2) && c.code.charAt(b1) == c.code.charAt(b2));
} else if (wildcard && wildcard.length == 5) {
// wildcard
result = result.filter(c => {
for (let i = 0; i < wildcard.length; i++) {
const card = wildcard[i];
const char = c.code.charAt(i + 1);
if (card != '*') {
if (card == 'Z' && char.isNumber()) return false;
if (card.isNumber() && card != char) return false;
}
}
return true;
});
} else {
document.querySelector('#result').innerHTML = '';
return;
}
const html = result.map(r => `<li title="${r.date}"><span class="c1">${r.code.slice(0, 1)}</span>
${r.code.slice(1).split('').map(c => c.isNumber() ? c : `<span class="c2">${c}</span>`).join('')} <span class="c3">${r.date}</span></li>`).join('\n');
document.querySelector('#result').innerHTML = html;
}
function reloadExcludes() {
reload();
}
function reloadPattern() {
document.querySelector('#wildcard').value = '';
reload();
}
function reloadWildcard() {
document.querySelector('#pattern').selectedIndex = 0;
const wildcard = document.querySelector('#wildcard').value.split('').filter(c => c.trim().length > 0);
if (wildcard.length == 5) reload();
}
function generateCode(range) {
const chars = range.slice(1);
const codes = [];
for (let i = 0; i < 100; i++) {
const [c1, c2] = i.toString().padStart(2, '0').split('');
const code = range.slice(0, 1) + chars.replace('*', c1).replace('*', c2);
codes.push(code);
}
return codes;
}
async function run() {
const res = await fetch('carplates.json');
const data = await res.json();
codePool.splice(0, 0, ...data);
console.log(codePool.length);
reload();
}
run();
</script>
<div class="filters">
<select id="dateFrom" onchange="reload()">
<option>2021</option>
<option>2020</option>
<option>2019</option>
<option>2018</option>
<option>2017</option>
<option>2016</option>
</select>
<input id="excludes" placeholder="排除的字符" value="E I O P R S 4" onchange="reloadExcludes()" />
<select id="pattern" onchange="reloadPattern()">
<option></option>
<optgroup label="AABB">
<option>AZABB</option>
<option>AAZBB</option>
<option>AABZB</option>
</optgroup>
<optgroup label="ABAB">
<option>AZBAB</option>
<option>ABZAB</option>
<option>ABAZB</option>
</optgroup>
<!--
<optgroup label="ABCD">
<option>ZABCD</option>
<option>AZBCD</option>
<option>ABZCD</option>
<option>ABCZD</option>
<option>ABCDZ</option>
</optgroup>
-->
</select>
<input maxlength="5" style="text-transform:uppercase" placeholder="91*Z1" id="wildcard" onchange="reloadWildcard()">
</div>
<ul id="result"></ul>
</body>
</html>