-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.htm
223 lines (196 loc) · 5.18 KB
/
index.htm
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
<!doctype html>
<html lang="en" class="scroll-smooth">
<head>
<meta charset="utf-8">
</head>
<body>
<style>
body {
color: #fff;
font-family: arial;
font-size: 11px;
background-color: #143d5e;
}
table {
border: none;
border-spacing: 6px;
}
td
{
background-color: #ccc;
padding: 0px;
font-size: 13px;
color: #000;
}
.id {
display: block;
padding: 6px;
background: #2d76b3;
color: #fff;
font-weight: bold;
cursor: pointer;
}
.question {
display: block;
padding: 6px;
}
#modal {
position: absolute;
width: 200px;
height: 300px;
border: 1px solid black;
background-color: #ccc;
display: block;
z-index: 100;
top: 0;
left: 0;
}
.modalHeader {
display: block;
background-color: #333;
font-size: 14px;
height: 27px;
}
.modalHeader .modalClose {
float: right;
font-weight: bold;
cursor: pointer;
background-color: #666;
padding: 5px;
}
.modalHeader .modalTitle {
width: 92%;
overflow-x: hidden;
display: block;
padding: 5px;
}
.modalContent {
display: block;
color: #333;
font-size: 13px;
height: 91%;
overflow-y: scroll;
}
.modalContent div {
padding: 5px;
margin-bottom: 1px;
}
.marked {
background-color: #fff325;
}
</style>
<h1>Botpress QNA Duplicate Finder</h1>
Copyright by Frank Dase (2022)<br/><br/>
<input type="file" id="fileUpload" onchange="getPath(this.files)">
<div id="output"></div>
<div id="modal">
<div class="modalHeader"><span class="modalClose" onclick="closeModal()">X</span><span class="modalTitle"></span></div>
<div class="modalContent"></div>
</div>
<script>
// -----------------------------------------------
// global variables
// -----------------------------------------------
const modal = document.getElementById('modal');
let questionsArray = [];
let resultsArray = [];
const pickDoublicates = async (json) => {
const container = document.getElementById("output");
questionsArray = [];
resultsArray = [];
let count = 0;
// convert json to a better readable format
json.qnas.forEach((item) => {
const questions = [];
item.data.questions.de.forEach((q) => {
questions.push(q.toLowerCase());
});
questionsArray.push({"id": item.id, "questions" : questions});
});
// check data and show result
let output = "<hr>";
output += "<h2 id='results'>Results</h2>";
output += "<table >";
questionsArray.map(item => {
item.questions.map(question => {
questionsArray.map(i => {
const index = i.questions.indexOf(question);
if(index>-1)
{
if(item.id !== i.id)
{
// show result only one time
var index1 = resultsArray.findIndex(e => e.id === item.id && e.question == question);
var index2 = resultsArray.findIndex(e => e.id === i.id && e.question == i.questions[index]);
if(index1 === -1 || index2 === -1)
{
output += "<tr>";
output += "<td><div class='id' onclick='openModal(this)' title='show all questions of this ID'>" + item.id + "</div><div class='question'>" + question + "</div></td>";
output += "<td><div class='id' onclick='openModal(this)' title='show all questions of this ID'>" + i.id + "</div><div class='question'>" + i.questions[index] + "</div></td>";
output += "</tr>";
resultsArray.push({id:item.id, question: question});
resultsArray.push({id:i.id , question: i.questions[index]});
count++;
}
}
}
});
});
});
output += "</table>";
container.innerHTML = output;
document.getElementById("results").innerHTML = document.getElementById("results").innerHTML + " (" + count + ")";
}
const getPath = (file) => {
// Stop the form from reloading the page
event.preventDefault();
// If there's no file, do nothing
if (!file[0].size) return;
// Create a new FileReader() object
let reader = new FileReader();
// Setup the callback event to run when the file is read
reader.onload = logFile;
// Read the file
reader.readAsText(file[0]);
}
function logFile (event) {
let str = event.target.result;
let json = JSON.parse(str);
pickDoublicates(json);
}
const openModal = (el) =>
{
modal.style.display = "block";
const header = modal.getElementsByClassName("modalTitle");
const modalContent = modal.getElementsByClassName("modalContent");
const offset = el.getBoundingClientRect();
modal.style.left = parseInt(offset.left)+"px";
modal.style.top = parseInt(offset.top)+ window.scrollY +"px";
modal.style.width = offset.width + "px";
let id = el.innerHTML;
header[0].innerHTML = el.innerHTML;
modalContent[0].innerHTML = "";
questionsArray.map(item => {
if(item.id == id)
{
item.questions.map(question => {
const qIndex = resultsArray.findIndex(e => e.question == question);
if(qIndex > -1)
{
modalContent[0].innerHTML += `<div class='marked'>${question}</div>`;
} else {
modalContent[0].innerHTML += `<div>${question}</div>`;
}
});
}
});
}
const closeModal = () => {
modal.style.display = "none";
}
onload = ( ()=> {
closeModal();
});
</script>
</body>
</html>