-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAliasDetector.html
228 lines (188 loc) · 8.28 KB
/
AliasDetector.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
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Alias Detector</title>
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-4bw+/aepP/YC94hEpVNVgiZdgIC5+VKNBQNGCHeKRQN+PtmoHDEXuppvnDJzQIu9" crossorigin="anonymous">
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-HwwvtgBNo3bZJJLYd8oVXjrBZt8cqVSpeBNS5n7C8IVInixGAoxmnlMuBnhbgrkm"
crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.18.5/xlsx.mini.min.js"></script>
<style>
html,
body {
height: calc(100% - 50px);
}
</style>
</head>
<body>
<div class="container-fluid h-100">
<div class="row p-2">
<div class="col-3 d-flex justify-content-between h-100">
<span class="d-flex align-items-end">
<h2 class="text-primary">Alias Detector</h2>
<h6 class="mt-2 m-0 p-0 text-primary opacity-25">bro edition</h6>
</span>
</div>
<div class="col pt-2 d-flex justify-content-between h-100">
<input type="file" id="upload" class="btn btn-light" />
<input type="button" id="save" value="Save" class="btn btn-light" />
</div>
</div>
<div class="row p-3 h-100">
<div class="col-1">
<p class="text-center fw-bolder">#</p>
<div class="row p-2 h-100">
<div id="indexes" class="col text-center d-flex flex-column align-items-center h-100"></div>
</div>
</div>
<div class="col-4">
<p class="text-center fw-bolder">Names</p>
<div class="row p-2 h-100">
<div id="names" class="col border border-secondary rounded shadow h-100"></div>
</div>
</div>
<div class="col-5">
<p class="text-center fw-bolder">Alias</p>
<div class="row p-2 h-100">
<div id="alias" class="col border border-secondary rounded shadow d-flex flex-column h-100"></div>
</div>
</div>
<div class="col-2">
<p class="text-center fw-bolder">Filters</p>
<div class="row p-2 h-100">
<div id="filters" class="col border border-secondary rounded shadow d-flex flex-column h-100"></div>
</div>
</div>
</div>
</div>
<script>
// Show a popup before page refresh
window.onbeforeunload = () => "";
const namesSelector = document.querySelector("#names");
const indexesSelector = document.querySelector("#indexes");
const filtersSelector = document.querySelector("#filters");
const saveBtnSelector = document.querySelector("#save");
const uploadBtnSelector = document.querySelector("#upload");
let names = new Set();
let alias = new Map();
let filters = new Set();
namesSelector.addEventListener("click", (event) => {
updateFilters(event.target.textContent);
updateAlias();
});
filtersSelector.addEventListener("click", (event) => {
const text = event.target.textContent;
filters.delete(text);
filtersSelector.removeChild(event.target);
Array.from(namesSelector.querySelectorAll("*")).forEach(s => {
if (s.textContent.toLowerCase() == text.toLowerCase()) {
s.classList.toggle("text-decoration-line-through");
}
})
updateAlias();
});
saveBtnSelector.addEventListener("click", () => {
const json = JSON.stringify({ Alias: alias, Filters: Array.from(filters) }, null, 2);
const blob = new Blob([json], { type: "application/json" });
const link = document.createElement("a");
link.href = URL.createObjectURL(blob);
link.download = "data.json";
link.click();
URL.revokeObjectURL(link.href);
});
uploadBtnSelector.addEventListener("change", (event) => {
names = new Set();
alias = new Map();
filters = new Set();
clearHtml("#indexes");
clearHtml("#names");
clearHtml("#alias");
clearHtml("#filters");
const file = event.target.files[0];
if (file) {
const fileReader = new FileReader();
fileReader.onload = function (event) {
const data = event.target.result;
const workbook = XLSX.read(data, { type: 'binary' });
const firstSheetName = workbook.SheetNames[0];
const firstSheet = workbook.Sheets[firstSheetName];
for (const cell in firstSheet) {
if (cell.startsWith('A')) {
const valueA = firstSheet[cell].v;
if (/[^0-9.-]/.test(valueA)) {
names.add(valueA);
}
}
}
updateAlias();
Array.from(names).forEach((value, index) => {
const words = value.split(" ");
var div = document.createElement("div");
words.forEach(word => {
const span = document.createElement('span');
span.setAttribute("role", "button");
span.classList.add("p-1");
span.textContent = word;
div.appendChild(span);
});
namesSelector.appendChild(div);
const span = document.createElement("span");
span.textContent = `${index + 1}`;
indexesSelector.appendChild(span);
});
};
fileReader.readAsBinaryString(file);
}
});
function updateFilters(text) {
Array.from(namesSelector.querySelectorAll("*"))
.filter(s => s.textContent.toLowerCase() == text.toLowerCase())
.forEach(s => s.classList.toggle("text-decoration-line-through"));
if (!filters.has(text)) {
filters.add(text);
} else {
filters.delete(text);
}
// Re-render
clearHtml("#filters");
Array.from(filters).sort().forEach(filter => {
const span = document.createElement("span");
span.setAttribute("role", "button");
span.textContent = filter
span.classList.add("p-1");
filtersSelector.appendChild(span);
});
}
function updateAlias() {
alias = Array.from(names).reduce((groups, item) => {
let key = item.toUpperCase();
key = key.split(" ").filter(s => !Array.from(filters).map(s => s.toUpperCase()).includes(s)).join(" ");
if (!groups[key]) {
groups[key] = [];
}
groups[key].push(item);
return groups;
}, {});
// Re-render
clearHtml("#alias");
Object.keys(alias).filter(s => s != "").sort().forEach(key => {
const value = alias[key];
const div = document.createElement("div");
div.classList.add("p-1");
div.innerHTML = `<strong>${key}</strong> - ${value.join(", ")}`;
document.querySelector("#alias").appendChild(div);
});
}
function clearHtml(parentTag) {
const parentElement = document.querySelector(parentTag);
if (parentElement) {
const childElements = parentElement.querySelectorAll("*");
childElements.forEach(child => child.remove());
}
}
</script>
</body>
</html>