---
# System prepended metadata

title: Chrome-GPT popup.js

---

# Chrome-GPT popup.js
<!DOCTYPE html>
<html>
<head>
  <style>
    body {
      font-family: Arial, sans-serif;
      padding: 15px;
      width: 300px;
    }
    input[type="checkbox"] {
      width: 20px;
      height: 20px;
    }
    .toggle-label {
      font-size: 16px;
      margin-left: 10px;
    }
  </style>
</head>
<body>
  <h2>GPT-Chrome</h2>
  <p>
    <input type="checkbox" id="toggle">
    <label for="toggle" class="toggle-label">Turn extension on/off</label>
  </p>
  <p>Type your complex prompt here:</p>
  <textarea id="userPrompt" rows="4" cols="30"></textarea>
</body>
</html>

const apiKey = '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';

async function sendToChatGPT(prompt) {
  const response = await fetch('https://api.openai.com/v1/engines/davinci-codex/completions', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json',
      'Authorization': `Bearer ${apiKey}`
    },
    body: JSON.stringify({
      prompt: prompt,
      max_tokens: 50,
      n: 1,
      stop: null,
      temperature: 1
    })
  });

  const data = await response.json();
  return data.choices[0].text;
}

document.getElementById('toggle').addEventListener('change', (event) => {
  if (event.target.checked) {
    const prompt = document.getElementById('prompt').value;
    chrome.runtime.sendMessage({ type: 'executeTasks', prompt: prompt });
  }
});