-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
395 lines (283 loc) · 13.5 KB
/
script.js
File metadata and controls
395 lines (283 loc) · 13.5 KB
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
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
document.addEventListener('DOMContentLoaded', function () {
const chatButton = document.getElementById('chat-button');
const summaryButton = document.getElementById('summary-button');
const imageButton = document.getElementById('image-button');
const webButton = document.getElementById('web-button');
const chatSection = document.getElementById('chat-section');
const summarySection = document.getElementById('summary-section');
const imageSection = document.getElementById('image-section');
const webSection = document.getElementById('web-section');
chatButton.addEventListener('click', function () {
chatSection.style.display = 'block';
summarySection.style.display = 'none';
imageSection.style.display = 'none';
webSection.style.display = 'none';
});
summaryButton.addEventListener('click', function () {
chatSection.style.display = 'none';
summarySection.style.display = 'block';
imageSection.style.display = 'none';
webSection.style.display = 'none';
});
imageButton.addEventListener('click', function () {
chatSection.style.display = 'none';
summarySection.style.display = 'none';
imageSection.style.display = 'block';
webSection.style.display = 'none';
});
webButton.addEventListener('click', function () {
chatSection.style.display = 'none';
summarySection.style.display = 'none';
imageSection.style.display = 'none';
webSection.style.display = 'block';
});
// Rest of your code...
// function myFunction() {
// var x = document.getElementById("chat-section");
// if (x.style.display === "none") {
// x.style.display = "block";
// } else {
// x.style.display = "none";
// }
// }
// chat section
const questionInput = document.getElementById('question_chat');
const submitButton = document.getElementById('submit_chat');
const responseDiv = document.getElementById('response_chat');
//loading
const rotate = document.getElementById('chatbot-content');
submitButton.addEventListener('click', async function () {
responseDiv.innerText = "Your response will be shown here..."
//loading activated
rotate.classList.add("rainbow")
const question = questionInput.value.trim();
const apiUrl = 'https://mindflow-u5hy.onrender.com/chat'; // Change the API route as needed
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ question })
});
if (response.ok) {
const data = await response.json();
console.log(data)
const markdownText = data.response;
console.log('Original Markdown:', markdownText)
const markedOptions ={
sanitize: false
}
const htmlText = marked(markdownText, markedOptions);
console.log('HTML Output:', htmlText);
responseDiv.innerHTML= htmlText;
//loading remove
rotate.classList.remove("rainbow")
const copyButton = document.getElementById('chat-copyButton');
copyButton.addEventListener('click', function () {
// Select the response text
const responseText = responseDiv.innerText;
const tempTextArea = document.createElement('textarea');
tempTextArea.value = responseText;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');
document.body.removeChild(tempTextArea);
// Change button text to indicate successful copy
copyButton.innerText = "✅";
setTimeout(() => {
copyButton.innerText = '📋';
}, 1500); // Reset button text after 1.5 seconds
});
} else {
responseDiv.textContent = 'Error: Unable to fetch response.';
}
});
//context section
const questionInput_2 = document.getElementById('question_data');
const dataInput_2 = document.getElementById('data_data');
const submitButton_2 = document.getElementById('submit_data');
const responseDiv_2 = document.getElementById('response_data');
submitButton_2.addEventListener('click', async function () {
responseDiv_2.innerText = "Your data will be shown here..."
//loading
rotate.classList.add("rainbow")
const question = questionInput_2.value;
const context = (dataInput_2.value).replace(/\s+/g, '').trim();
console.log(context)
const apiUrl = 'https://mindflow-u5hy.onrender.com/context';
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ question, context })
});
if (response.ok) {
const data = await response.json();
const markdownText = data;
console.log(data)
console.log('Original Markdown:', markdownText)
const markedOptions ={
sanitize: false
}
const htmlText = marked(markdownText, markedOptions);
console.log('HTML Output:', htmlText);
responseDiv_2.innerHTML= htmlText;
//loading remove
rotate.classList.remove("rainbow")
const copyButton = document.getElementById('summary-copyButton');
copyButton.addEventListener('click', function () {
// Select the response text
const responseText = responseDiv_2.innerText;
const tempTextArea = document.createElement('textarea');
tempTextArea.value = responseText;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');
document.body.removeChild(tempTextArea);
// Change button text to indicate successful copy
copyButton.innerText = "✅";
setTimeout(() => {
copyButton.innerText = '📋';
}, 1500); // Reset button text after 1.5 seconds
});
} else {
responseDiv_2.textContent = 'Error: Unable to fetch response.';
}
});
//Image Section
const questionInput_3 = document.getElementById('question_image');
// const dataInput_3 = document.getElementById('data_image');
const submitButton_3 = document.getElementById('submit_image');
const responseDiv_3 = document.getElementById('response_image');
submitButton_3.addEventListener('click', async function () {
responseDiv_3.innerText = "Copy the image url shown here..."
//loading
rotate.classList.add("rainbow")
const base = questionInput_3.value.trim();
// const extra = " ";
const apiUrl = 'https://mindflow-u5hy.onrender.com/image';
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ base })
});
if (response.ok) {
const data = await response.json();
console.log(data)
// const markdownText = data;
// console.log(data)
// console.log('Original Markdown:', markdownText)
// const markedOptions ={
// sanitize: false
// }
// const htmlText = marked(markdownText, markedOptions);
// console.log('HTML Output:', htmlText);
// const result = htmlText.match(/\<a\>.+\<\/a\>/)
// console.log(result);
var url = data;
var input = document.createElement("input");
input.type = "text";
input.value = url;
input.size = "30";
input.style.textOverflow = "ellipsis";
var container = document.getElementById("response_image");
responseDiv_3.innerText = ""
container.appendChild(input);
const copyButton = document.getElementById('image-copyButton');
copyButton.addEventListener('click', function () {
// Select the response text
const responseText = url;
const tempTextArea = document.createElement('textarea');
tempTextArea.value = responseText;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');
document.body.removeChild(tempTextArea);
// Change button text to indicate successful copy
copyButton.innerText = "✅";
setTimeout(() => {
copyButton.innerText = '📋';
}, 1500); // Reset button text after 1.5 seconds
});
// var input = document.createElement("input");
// input.type = "text";
// input.value = url;
// input.size = "30";
// input.style.textOverflow = "ellipsis";
// // Create a new button element
// var button = document.createElement("button");
// button.innerHTML = "Copy";
// button.classList.add("submit")
// button.onclick = function() {
// input.select();
// document.execCommand("copy");
// };
// // Append the input and button elements to the url-container div
// var container = document.getElementById("response_image");
// container.appendChild(input);
// container.appendChild(button)
rotate.classList.remove("rainbow")
// container.appendChild(button)
// responseDiv_3.innerHTML= htmlText;
//loading remove
} else {
responseDiv_3.textContent = 'Error: Unable to fetch response.';
}
});
//Web Section
const questionInput_4 = document.getElementById('question_web');
const dataInput_4 = document.getElementById('data_web');
const submitButton_4 = document.getElementById('submit_web');
const responseDiv_4 = document.getElementById('response_web');
submitButton_4.addEventListener('click', async function () {
responseDiv_4.innerText = "Your response will be shown here..."
//loading
rotate.classList.add("rainbow")
const question = questionInput_4.value;
const context = dataInput_4.value;
console.log(context)
const apiUrl = 'https://mindflow-u5hy.onrender.com/web';
const response = await fetch(apiUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({ question, context })
});
if (response.ok) {
const data = await response.json();
const markdownText = data;
console.log(data)
console.log('Original Markdown:', markdownText)
const markedOptions ={
sanitize: false
}
const htmlText = marked(markdownText, markedOptions);
console.log('HTML Output:', htmlText);
responseDiv_4.innerHTML= htmlText;
const copyButton = document.getElementById('web-copyButton');
copyButton.addEventListener('click', function () {
// Select the response text
const responseText = responseDiv_4.innerText;
const tempTextArea = document.createElement('textarea');
tempTextArea.value = responseText;
document.body.appendChild(tempTextArea);
tempTextArea.select();
document.execCommand('copy');
document.body.removeChild(tempTextArea);
// Change button text to indicate successful copy
copyButton.innerText = "✅";
setTimeout(() => {
copyButton.innerText = '📋';
}, 1500); // Reset button text after 1.5 seconds
});
//loading remove
rotate.classList.remove("rainbow")
} else {
responseDiv_4.textContent = 'Error: Unable to fetch response.';
}
});
});