Spaces:
Running
Running
Update script.js
Browse files
script.js
CHANGED
|
@@ -1,96 +1,92 @@
|
|
| 1 |
-
document.
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
const chatOutput = document.getElementById('chat-output');
|
| 6 |
-
|
| 7 |
-
const toneSelect = document.getElementById('tone-select');
|
| 8 |
-
const formatSelect = document.getElementById('format-select');
|
| 9 |
-
const lengthSelect = document.getElementById('length-select');
|
| 10 |
-
const languageSelect = document.getElementById('language-select');
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
clearInterval(currentInterval);
|
| 31 |
-
currentInterval = null;
|
| 32 |
-
// Show the "Copy & Open" button once typing is complete
|
| 33 |
-
copyAndOpenBtn.classList.remove('hidden');
|
| 34 |
-
}
|
| 35 |
-
}, speed);
|
| 36 |
}
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
const selectedTone = toneSelect.value;
|
| 50 |
-
const selectedFormat = formatSelect.value;
|
| 51 |
-
const selectedLength = lengthSelect.value;
|
| 52 |
-
const selectedLanguage = languageSelect.value;
|
| 53 |
-
|
| 54 |
-
const fullResponse = `Your Idea: "${idea}"
|
| 55 |
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
typeWriter(chatOutput, fullResponse, 30);
|
| 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 |
-
});
|
|
|
|
| 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;
|
| 9 |
+
const interval = setInterval(() => {
|
| 10 |
+
target.textContent += text.charAt(i);
|
| 11 |
+
i++;
|
| 12 |
+
if (i >= text.length) clearInterval(interval);
|
| 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 |
|
| 34 |
+
const detailsByLength = {
|
| 35 |
+
Short: language === 'English'
|
| 36 |
+
? 'A crisp, single-line value proposition.'
|
| 37 |
+
: 'مختصر اور مؤثر ایک جملے کی قدر پیش کش۔',
|
| 38 |
+
Medium: language === 'English'
|
| 39 |
+
? 'A concise summary with one or two supporting points.'
|
| 40 |
+
: 'مختصر خلاصہ ساتھ ایک دو اہم نکات۔',
|
| 41 |
+
Detailed: language === 'English'
|
| 42 |
+
? 'A detailed explanation with benefits, audience fit, and a gentle CTA.'
|
| 43 |
+
: 'تفصیلی وضاحت جس میں فوائد، ہدف صارف اور ہلکی سی کال ٹو ایکشن شامل ہو۔'
|
| 44 |
+
}[length];
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
+
const contentByFormat = {
|
| 47 |
+
'Paragraph': `${base.paragraph}${detailsByLength}`,
|
| 48 |
+
'Bullet Points': `${base.bulletsIntro}- ${detailsByLength}\n- Audience relevance\n- Clear next step`,
|
| 49 |
+
'Email': `${base.emailIntro}${detailsByLength}\n\nBest regards,\nYour Brand`
|
| 50 |
+
}[format];
|
| 51 |
|
| 52 |
+
return `${base.intro}${contentByFormat}${base.outro}`;
|
| 53 |
+
}
|
|
|
|
|
|
|
|
|
|
| 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');
|
| 71 |
+
}
|
| 72 |
|
| 73 |
+
async function copyToClipboard() {
|
| 74 |
+
const text = output.textContent.trim();
|
| 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);
|
|
|