Nuzwa commited on
Commit
b251fc3
·
verified ·
1 Parent(s): 3e5bad1

Update script.js

Browse files
Files changed (1) hide show
  1. script.js +22 -8
script.js CHANGED
@@ -4,6 +4,8 @@ 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',
@@ -93,19 +95,31 @@ function handleGenerate() {
93
  copyBtn.setAttribute('aria-live', 'polite');
94
  }
95
 
96
- async function copyToClipboard() {
 
 
 
 
97
  const text = output.textContent.trim();
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);
 
4
  const output = document.getElementById('chat-output');
5
  const copyBtn = document.getElementById('copy-and-open-btn');
6
 
7
+ const GPT_URL = 'https://chat.openai.com/'; // Replace with your Custom GPT URL if needed.
8
+
9
  const state = {
10
  tone: 'Friendly',
11
  format: 'Paragraph',
 
95
  copyBtn.setAttribute('aria-live', 'polite');
96
  }
97
 
98
+ async function copyAndOpenGPT() {
99
+ // Open GPT immediately (best chance to avoid popup blockers)
100
+ const opened = window.open(GPT_URL, '_blank');
101
+
102
+ // Then copy response text (if present)
103
  const text = output.textContent.trim();
 
104
  try {
105
+ if (text) {
106
+ await navigator.clipboard.writeText(text);
107
+ copyBtn.textContent = ' Copied! Opening GPT...';
108
+ } else {
109
+ copyBtn.textContent = '↗ Opening GPT...';
110
+ }
111
  } catch {
112
+ copyBtn.textContent = '⚠️ Copy failed • Opening GPT';
113
+ } finally {
114
+ setTimeout(() => (copyBtn.textContent = '📋 Copy & Paste Now'), 1600);
115
+ }
116
+
117
+ // Optional feedback if popup blocked
118
+ if (!opened) {
119
+ // Silent fallback; user can allow pop-ups from the browser UI.
120
  }
121
  }
122
 
123
  startBtn.addEventListener('click', handleGenerate);
124
  ideaInput.addEventListener('keydown', (e) => { if (e.key === 'Enter') handleGenerate(); });
125
+ copyBtn.addEventListener('click', copyAndOpenGPT);