Empereur-Pirate commited on
Commit
f72c84a
·
verified ·
1 Parent(s): be0d579

Update static/script.js

Browse files
Files changed (1) hide show
  1. static/script.js +2 -40
static/script.js CHANGED
@@ -7,45 +7,7 @@ function revealContent() {
7
 
8
  // Call the function once the DOM is loaded
9
  document.addEventListener('DOMContentLoaded', () => {
10
- // Connect to the endpoint and parse JSON response
11
- const initConnection = async () => {
12
- try {
13
- // Fetch the endpoint
14
- const connectionResult = await fetch('/generate_text');
15
-
16
- // Parse the JSON response
17
- if (!connectionResult.ok) {
18
- throw Error(await connectionResult.text());
19
- }
20
-
21
- const json = await connectionResult.json();
22
- console.log(json);
23
- } catch (err) {
24
- // Display the err object and wait for 2 sec before retrying
25
- console.error(err);
26
- setTimeout(() => initConnection(), 2000);
27
- return;
28
- } finally {
29
- // Clear timeouts and intervals
30
- clearTimeout(timeoutId);
31
- clearInterval(intervalId);
32
- }
33
-
34
- // Connection established, remove loader animation
35
- revealContent();
36
- };
37
-
38
- // Timeout logic for waiting for endpoint availability
39
- let timeoutId, intervalId;
40
- timeoutId = setTimeout(() => {
41
- intervalId = setInterval(() => {
42
- console.warn('Endpoint timed out, retrying...');
43
- initConnection();
44
- }, 2000);
45
- }, 5000);
46
-
47
- // Attempt to connect to the endpoint
48
- initConnection();
49
  });
50
 
51
  const textGenForm = document.querySelector(".text-gen-form");
@@ -71,4 +33,4 @@ textGenForm.addEventListener("submit", async (event) => {
71
  const textGenParagraph = document.querySelector(".text-gen-output");
72
 
73
  textGenParagraph.textContent = await generateText(textGenInput.value);
74
- });
 
7
 
8
  // Call the function once the DOM is loaded
9
  document.addEventListener('DOMContentLoaded', () => {
10
+ revealContent();
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
11
  });
12
 
13
  const textGenForm = document.querySelector(".text-gen-form");
 
33
  const textGenParagraph = document.querySelector(".text-gen-output");
34
 
35
  textGenParagraph.textContent = await generateText(textGenInput.value);
36
+ });