-
Notifications
You must be signed in to change notification settings - Fork 1
/
script.js
150 lines (115 loc) · 4.99 KB
/
script.js
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
// Get the button and content elements
let simpleBtn = document.getElementById("simple-btn");
let simplecontent = document.getElementById("simplecontent");
let expertBtn = document.getElementById("expert-btn");
let uploadBtn = document.getElementById("upload-button")
let expertcontent = document.getElementById("expertcontent");
let tabArea = document.getElementById("tab-area")
const typewriter = document.getElementById('typewriter');
const gitSummary = document.getElementById("git-summary");
const text = gitSummary.textContent;
let inputText = String;
function generateSummary() {
tabArea.style.display ="block";
var inputText = document.getElementById("input-text").value;
var xhr = new XMLHttpRequest();
// Set up the request
xhr.open("POST", "/process-text", true);
xhr.setRequestHeader("Content-Type", "application/json");
// Define the request payload
var payload = {
text: inputText
};
// Convert the payload to JSON string
var payloadJson = JSON.stringify(payload);
// Set up the event handler for when the response is received
xhr.onreadystatechange = function () {
if (xhr.readyState === 4 && xhr.status === 200) {
var response = JSON.parse(xhr.responseText);
var summary = response.summary; // Get the 'summary' property from the response object
var expertsummary = response.expertsummary; // Get the expert property from response
var summaryTextArea = document.getElementById("simplecontent");
var paragraph = document.getElementById("git-summary"); // Get the existing paragraph element
// Display otherValue in 'expertcontent' div
var expertTextArea = document.getElementById("expertcontent");
var expertparagraph = document.getElementById("expertsummary"); // Get the existing paragraph element
var indexSummary = 0; // Current index of the summary text
var indexExpertSummary = 0; // Current index of the expertsummary text
var delay = 20; // Delay between each character (adjust as needed)
// Function to update the text content with a delayed effect
function updateSummaryText() {
// Get a portion of the summary text based on the current index
var partialSummary = summary.substring(0, indexSummary);
// Update the text content of the paragraph
paragraph.textContent = partialSummary;
// Increment the index
indexSummary++;
// Check if there are more characters to update
if (indexSummary <= summary.length) {
// Call the function recursively after the delay
setTimeout(updateSummaryText, delay);
}
}
// Function to update the expertsummary text content with a delayed effect
function updateExpertSummaryText() {
// Get a portion of the expertsummary text based on the current index
var partialExpertSummary = expertsummary.substring(0, indexExpertSummary);
// Update the text content of the expertparagraph
expertparagraph.textContent = partialExpertSummary;
// Increment the index
indexExpertSummary++;
// Check if there are more characters to update
if (indexExpertSummary <= expertsummary.length) {
// Call the function recursively after the delay
setTimeout(updateExpertSummaryText, delay);
}
}
// Start updating the summary text content with a delayed effect
updateSummaryText();
// Start updating the expertsummary text content with a delayed effect
updateExpertSummaryText();
}
};
// Send the request
xhr.send(payloadJson);
}
window.addEventListener("load",()=>{
function toggleSimpleContent() {
if(simpleBtn.value == "OFF"){
simplecontent.style.display = "block";
simpleBtn.value = "ON";
}
else if (simpleBtn.value == "ON")
{
simplecontent.style.display = "none";
simpleBtn.value = "OFF";
}
}
// Function to toggle the display of the expert content
function toggleExpertContent() {
if (expertBtn.value == "OFF") {
expertcontent.style.display = "block";
expertBtn.value = "ON";
}
else if (expertBtn.value == "ON") {
expertcontent.style.display = "none";
expertBtn.value = "OFF";
}
}
simpleBtn.addEventListener("click", toggleSimpleContent);
expertBtn.addEventListener("click", toggleExpertContent);
uploadBtn.addEventListener("click",generateSummary);
// let index = 0;
// function type() {
// if (index < text.length) {
// typewriter.innerHTML = text.slice(0, index) + '<span class="blinking-cursor">|</span>';
// index++;
// setTimeout(type, Math.random() * 100 +20 );
// } else {
// typewriter.innerHTML = text.slice(0, index) + '<span class="blinking-cursor">|</span>';
// }
// }
// // start typing
// type();
})
// export { inputText };