Nuzwa commited on
Commit
3115bd2
·
verified ·
1 Parent(s): 9be8966

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +40 -21
script.js CHANGED
@@ -1,8 +1,32 @@
1
  const ideaInput = document.getElementById('idea-input');
 
2
  const startBtn = document.getElementById('start-chat-btn');
3
  const output = document.getElementById('chat-output');
4
  const copyBtn = document.getElementById('copy-and-open-btn');
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  function typewriter(text, target, speed = 18) {
7
  target.textContent = '';
8
  let i = 0;
@@ -13,21 +37,21 @@ function typewriter(text, target, speed = 18) {
13
  }, speed);
14
  }
15
 
16
- function formatResponse({ idea, tone, format, length, language }) {
17
  const base = {
18
  English: {
19
- intro: `Idea: ${idea}\nTone: ${tone} • Format: ${format} • Length: ${length}\n\n`,
20
  paragraph: `Here’s a ${tone.toLowerCase()} take on your idea. `,
21
  bulletsIntro: `Key points:\n`,
22
- emailIntro: `Subject: ${idea}\n\nHi there,\n\n`,
23
  outro: `\n\n— Generated by Brand AI`
24
  },
25
  Urdu: {
26
- intro: `آئیڈیا: ${idea}\nلہجہ: ${tone} • فارمیٹ: ${format} • طوالت: ${length}\n\n`,
27
  paragraph: `یہ آپ کے آئیڈیا پر ایک ${tone} انداز ہے۔ `,
28
  bulletsIntro: `اہم نکات:\n`,
29
- emailIntro: `موضوع: ${idea}\n\nالسلام علیکم،\n\n`,
30
- outro: `\n\n— برانڈ اے آئی کی جانب سے`
31
  }
32
  }[language];
33
 
@@ -54,17 +78,16 @@ function formatResponse({ idea, tone, format, length, language }) {
54
 
55
  function handleGenerate() {
56
  const idea = ideaInput.value.trim();
57
- if (!idea) {
 
 
58
  ideaInput.focus();
59
- output.textContent = 'Please enter an idea to get started.';
60
  return;
61
  }
62
- const tone = document.getElementById('tone-select').value;
63
- const format = document.getElementById('format-select').value;
64
- const length = document.getElementById('length-select').value;
65
- const language = document.getElementById('language-select').value;
66
 
67
- const text = formatResponse({ idea, tone, format, length, language });
 
68
  typewriter(text, output);
69
  copyBtn.classList.remove('hidden');
70
  copyBtn.setAttribute('aria-live', 'polite');
@@ -75,18 +98,14 @@ async function copyToClipboard() {
75
  if (!text) return;
76
  try {
77
  await navigator.clipboard.writeText(text);
78
- copyBtn.textContent = '✅ Copied! Open in Custom GPT';
79
- setTimeout(() => (copyBtn.textContent = '📋 Copy & Open in Custom GPT'), 1500);
80
- // Optional: open a placeholder URL for your Custom GPT
81
- // window.open('https://chat.openai.com/', '_blank');
82
  } catch {
83
  copyBtn.textContent = '⚠️ Copy failed';
84
- setTimeout(() => (copyBtn.textContent = '📋 Copy & Open in Custom GPT'), 1500);
85
  }
86
  }
87
 
88
  startBtn.addEventListener('click', handleGenerate);
89
- ideaInput.addEventListener('keydown', (e) => {
90
- if (e.key === 'Enter') handleGenerate();
91
- });
92
  copyBtn.addEventListener('click', copyToClipboard);
 
1
  const ideaInput = document.getElementById('idea-input');
2
+ const longInput = document.getElementById('long-input');
3
  const startBtn = document.getElementById('start-chat-btn');
4
  const output = document.getElementById('chat-output');
5
  const copyBtn = document.getElementById('copy-and-open-btn');
6
 
7
+ const state = {
8
+ tone: 'Friendly',
9
+ format: 'Paragraph',
10
+ length: 'Short',
11
+ language: 'English'
12
+ };
13
+
14
+ function handleToggle(e){
15
+ const btn = e.target.closest('.toggle');
16
+ if(!btn) return;
17
+ const row = btn.parentElement;
18
+ const group = row.dataset.group;
19
+
20
+ row.querySelectorAll('.toggle').forEach(b=>{
21
+ b.classList.remove('selected');
22
+ b.setAttribute('aria-pressed','false');
23
+ });
24
+ btn.classList.add('selected');
25
+ btn.setAttribute('aria-pressed','true');
26
+ state[group] = btn.dataset.value;
27
+ }
28
+ document.querySelectorAll('.btn-row').forEach(r=>r.addEventListener('click', handleToggle));
29
+
30
  function typewriter(text, target, speed = 18) {
31
  target.textContent = '';
32
  let i = 0;
 
37
  }, speed);
38
  }
39
 
40
+ function formatResponse({ idea, details, tone, format, length, language }) {
41
  const base = {
42
  English: {
43
+ intro: `Idea: ${idea || '—'}\nDetails: ${details || '—'}\nTone: ${tone} • Format: ${format} • Length: ${length}\n\n`,
44
  paragraph: `Here’s a ${tone.toLowerCase()} take on your idea. `,
45
  bulletsIntro: `Key points:\n`,
46
+ emailIntro: `Subject: ${idea || 'Your Idea'}\n\nHi there,\n\n`,
47
  outro: `\n\n— Generated by Brand AI`
48
  },
49
  Urdu: {
50
+ intro: `آئیڈیا: ${idea || '—'}\nتفصیل: ${details || '—'}\nلہجہ: ${tone} • فارمیٹ: ${format} • طوالت: ${length}\n\n`,
51
  paragraph: `یہ آپ کے آئیڈیا پر ایک ${tone} انداز ہے۔ `,
52
  bulletsIntro: `اہم نکات:\n`,
53
+ emailIntro: `موضوع: ${idea || 'آپ کا آئیڈیا'}\n\nالسلام علیکم،\n\n`,
54
+ outro: `\n\n— برانڈ اے آئی`
55
  }
56
  }[language];
57
 
 
78
 
79
  function handleGenerate() {
80
  const idea = ideaInput.value.trim();
81
+ const details = longInput.value.trim();
82
+
83
+ if (!idea && !details) {
84
  ideaInput.focus();
85
+ output.textContent = 'Please enter an idea or details to get started.';
86
  return;
87
  }
 
 
 
 
88
 
89
+ const { tone, format, length, language } = state;
90
+ const text = formatResponse({ idea, details, tone, format, length, language });
91
  typewriter(text, output);
92
  copyBtn.classList.remove('hidden');
93
  copyBtn.setAttribute('aria-live', 'polite');
 
98
  if (!text) return;
99
  try {
100
  await navigator.clipboard.writeText(text);
101
+ copyBtn.textContent = '✅ Copied! Paste Now';
102
+ setTimeout(() => (copyBtn.textContent = '📋 Copy & Paste Now'), 1500);
 
 
103
  } catch {
104
  copyBtn.textContent = '⚠️ Copy failed';
105
+ setTimeout(() => (copyBtn.textContent = '📋 Copy & Paste Now'), 1500);
106
  }
107
  }
108
 
109
  startBtn.addEventListener('click', handleGenerate);
110
+ ideaInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') handleGenerate(); });
 
 
111
  copyBtn.addEventListener('click', copyToClipboard);