-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
37 lines (31 loc) · 1.07 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
async function generateContent() {
const platform = document.getElementById('platform').value;
const promptType = document.getElementById('promptType').value;
let prompt;
if (promptType === 'predefined') {
prompt = document.getElementById('predefinedPrompts').value;
} else {
prompt = document.getElementById('customPrompt').value;
}
const requestBody = {
platform,
prompt
};
try {
const response = await fetch('http://localhost:3000/generate-content', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(requestBody)
});
if (!response.ok) {
throw new Error(`HTTP error! Status: ${response.status}`);
}
const data = await response.json();
const generatedContent = data.generatedContent;
document.getElementById('output').innerHTML = generatedContent;
} catch (error) {
console.error('Error:', error);
}
}