-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpassword.html
176 lines (172 loc) · 5.48 KB
/
password.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Password</title>
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/bootstrap-grid.min.css" rel="stylesheet">
<script src="js/jquery-3.3.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
<style>
.short {
width: 50px;
font-size: 30px;
}
</style>
</head>
<body>
<div class="container">
<nav class="navbar navbar-expand-sm bg-light">
<ul class="nav nav-tabs">
<li class="nav-item"><a class="nav-link" href="index.html">Home</a></li>
<li class="nav-item"><a class="nav-link" href="complicated-wires.html">Complicated Wires</a></li>
<li class="nav-item"><a class="nav-link" href="#">Wire Sequence</a></li>
<li class="nav-item"><a class="nav-link active" href="#">Password</a></li>
</ul>
</nav>
<div class="container">
<h1>Keep Talking Assistant
<small>Version 1 / Revision 3</small>
</h1>
<p>©2018 Inku Xuan</p>
<div class="card">
<div class="card-body">
<form id="form1" oninput="refreshResult()">
<table>
<thead>
<tr>
<th>D1</th>
<th>D2</th>
<th>D3</th>
</tr>
</thead>
<tr>
<td><input class="short" id="1-1" type="text" maxlength="1" tabindex="1"></td>
<td><input class="short" id="2-1" type="text" maxlength="1" tabindex="7"></td>
<td><input class="short" id="3-1" type="text" maxlength="1" tabindex="13"></td>
</tr>
<tr>
<td><input class="short" id="1-2" type="text" maxlength="1" tabindex="2"></td>
<td><input class="short" id="2-2" type="text" maxlength="1" tabindex="8"></td>
<td><input class="short" id="3-2" type="text" maxlength="1" tabindex="14"></td>
</tr>
<tr>
<td><input class="short" id="1-3" type="text" maxlength="1" tabindex="3"></td>
<td><input class="short" id="2-3" type="text" maxlength="1" tabindex="9"></td>
<td><input class="short" id="3-3" type="text" maxlength="1" tabindex="15"></td>
</tr>
<tr>
<td><input class="short" id="1-4" type="text" maxlength="1" tabindex="4"></td>
<td><input class="short" id="2-4" type="text" maxlength="1" tabindex="10"></td>
<td><input class="short" id="3-4" type="text" maxlength="1" tabindex="16"></td>
</tr>
<tr>
<td><input class="short" id="1-5" type="text" maxlength="1" tabindex="5"></td>
<td><input class="short" id="2-5" type="text" maxlength="1" tabindex="11"></td>
<td><input class="short" id="3-5" type="text" maxlength="1" tabindex="17"></td>
</tr>
<tr>
<td><input class="short" id="1-6" type="text" maxlength="1" tabindex="6"></td>
<td><input class="short" id="2-6" type="text" maxlength="1" tabindex="12"></td>
<td><input class="short" id="3-6" type="text" maxlength="1" tabindex="18"></td>
</tr>
</table>
</form>
</div>
</div>
<div class="jumbotron">
<h2 id="result">Enter letters</h2>
</div>
</div>
</div>
<script>
LETTER_COUNT = 6;
resultSet = [
"about", "after", "again", "below", "could",
"every", "first", "found", "great", "house",
"large", "learn", "never", "other", "place",
"plant", "point", "right", "small", "sound",
"spell", "still", "study", "their", "there",
"these", "thing", "think", "three", "water",
"where", "which", "world", "would", "write"
];
var candidates = [];
function refreshResult() {
let isFilledAny_ = [isFilledAny(1), isFilledAny(2), isFilledAny(3)];
candidates = [];
if (isFilledAny_[0])
//Search for col 1
for (let i = 1; i <= LETTER_COUNT; i++) {
if (isFilledAny_[1]) {
//If col 2 not blank, search col 2
for (let j = 1; j <= LETTER_COUNT; j++) {
if (isFilledAny_[2]) {
//If not blank, search col 3
for (let k = 1; k <= LETTER_COUNT; k++) {
let key = "" + $('#1-' + i).val() + $('#2-' + j).val() + $('#3-' + k).val();
if (key.length===3) {
console.log("pushing candidates using keyword " + key);
pushCandidatesByKeyword(key);
}
}
} else {
//for only 2 cols
let key = "" + $('#1-' + i).val() + $('#2-' + j).val();
if (key.length===2) {
console.log("pushing candidates using keyword " + key);
pushCandidatesByKeyword(key);
}
}
}
} else {
//for only 1 col
let key = "" + $('#1-' + i).val();
if (key.length===1) {
console.log("pushing candidates using keyword " + key);
pushCandidatesByKeyword(key);
}
}
}
console.log("Candidates showed.");
showCandidates();
}
/**
* Check if the specified column has any letter filled
* @param column
* @returns {boolean}
*/
function isFilledAny(column) {
for (i = 1; i <= LETTER_COUNT; i++) {
// noinspection EqualityComparisonWithCoercionJS
if ($("#" + column + "-" + i).val() !== "") {
return true;
}
}
return false;
}
function pushCandidatesByKeyword(keyword) {
resultSet.forEach(function (item, index) {
// noinspection EqualityComparisonWithCoercionJS
if (item.startsWith(keyword.toLowerCase()))
candidates.push(item);
});
}
function showCandidates() {
let resultNode = $("#result")
resultNode.html("");
if(candidates.length===0){
resultNode.html("<div class=\"alert alert-danger\">" +
"No candidate found. Check all letters!" +
"</div>")
} else {
candidates.forEach(function (item, index) {
resultNode.append(item);
if (index < candidates.length - 1)
resultNode.append("<br>");
});
}
}
</script>
</body>
</html>