diff --git a/content.js b/content.js index d6bf004..19b27d3 100644 --- a/content.js +++ b/content.js @@ -164,4 +164,4 @@ async function translateAllText(progressText, progressFill) { } return translatedCount; -} \ No newline at end of file +} diff --git a/manifest.json b/manifest.json index 34da0d4..969e298 100644 --- a/manifest.json +++ b/manifest.json @@ -1,43 +1,35 @@ { - "manifest_version": 3, - "name": "__MSG_extensionName__", - "description": "__MSG_extensionDescription__", - "default_locale": "en", - "version": "1.0", - "icons": { + "manifest_version": 3, + "name": "Hinglish Translator", + "version": "1.0", + "description": "Translate English text to Hinglish/Hindi using Groq API", + "permissions": ["storage", "contextMenus", "scripting", "tabs", "activeTab"], + "host_permissions": ["https://api.groq.com/*"], + "default_locale": "en", + "icons": { + "16": "icons/icon16.png", + "32": "icons/icon32.png", + "48": "icons/icon48.png", + "128": "icons/icon128.png" + }, + "background": { + "service_worker": "background.js", + "type": "module" + }, + "action": { + "default_popup": "popup/welcome.html", + "default_icon": { "16": "icons/icon16.png", "32": "icons/icon32.png", - "48": "icons/icon48.png", - "128": "icons/icon128.png" - }, - "permissions": [ - "storage", - "activeTab", - "contextMenus", - "scripting", - "tabs" - ], - "host_permissions": [ - "https://api.groq.com/*" - ], - "background": { - "service_worker": "background.js", - "type": "module" - }, - "action": { - "default_popup": "popup/welcome.html", - "default_icon": { - "16": "icons/icon16.png", - "32": "icons/icon32.png", - "48": "icons/icon48.png" - } - }, - "content_scripts": [ - { - "matches": [""], - "js": ["content.js"], - "css": ["styles/content.css"], - "run_at": "document_idle" - } - ] - } \ No newline at end of file + "48": "icons/icon48.png" + } + }, + "content_scripts": [ + { + "matches": [""], + "js": ["content.js"], + "css": ["styles/content.css"], + "run_at": "document_idle" + } + ] +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..f57c8a9 --- /dev/null +++ b/package-lock.json @@ -0,0 +1,13 @@ +{ + "name": "hinglish-ai-translator", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "hinglish-ai-translator", + "version": "1.0.0", + "license": "ISC" + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..f77cf0d --- /dev/null +++ b/package.json @@ -0,0 +1,13 @@ +{ + "name": "hinglish-ai-translator", + "version": "1.0.0", + "description": "A powerful and intuitive Chrome extension that brings seamless translation and AI-powered explanations to your browsing experience. Transform any English text into Hinglish (Hindi written in English letters) or Hindi with just a right-click!", + "main": "background.js", + "scripts": { + "start": "node background.js", + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC" +} diff --git a/popup/welcome.html b/popup/welcome.html index 76ef539..a952801 100644 --- a/popup/welcome.html +++ b/popup/welcome.html @@ -1,69 +1,9 @@ - + Hinglish Translator - Welcome - - + @@ -72,36 +12,14 @@

Welcome to Hinglish Translator

Please enter your Groq API key to enable translations:

- +

Your key will be stored locally in Chrome and only used for translation requests.

Don't have a key? Get one from Groq

- - + + diff --git a/popup/welcome.js b/popup/welcome.js index b6be485..1acf55a 100644 --- a/popup/welcome.js +++ b/popup/welcome.js @@ -1,85 +1,36 @@ -document.addEventListener('DOMContentLoaded', async () => { - // Check if API key exists - const { groqApiKey } = await chrome.storage.local.get(['groqApiKey']); - if (groqApiKey) { - window.location.href = 'popup.html'; - return; - } - - const apiKeyInput = document.getElementById('apiKeyInput'); - const saveButton = document.getElementById('saveApiKey'); - const errorMessage = document.createElement('div'); - errorMessage.style.color = '#d93025'; - errorMessage.style.marginTop = '10px'; - document.querySelector('.setup').appendChild(errorMessage); - - saveButton.addEventListener('click', async () => { - const apiKey = apiKeyInput.value.trim(); - if (!apiKey) { - errorMessage.textContent = 'Please enter your API key'; - return; - } - - try { - // Save API key first - await chrome.storage.local.set({ groqApiKey: apiKey }); - - // Test the API key with a simple request - const response = await fetch('https://api.groq.com/openai/v1/chat/completions', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'Authorization': `Bearer ${apiKey}` - }, - body: JSON.stringify({ - messages: [{ - role: "user", - content: "Hello" - }], - model: "meta-llama/llama-4-scout-17b-16e-instruct", - temperature: 0.7, - max_tokens: 10 - }) - }); - - if (!response.ok) { - const errorData = await response.json().catch(() => ({})); - throw new Error(errorData.error?.message || `API error: ${response.status}`); - } +const themeToggle = document.getElementById('themeToggle'); +const body = document.body; - // If we get here, the API key is valid - window.location.href = 'popup.html'; - } catch (error) { - console.error('API Key validation error:', error); - // Remove invalid key - await chrome.storage.local.remove(['groqApiKey']); - errorMessage.textContent = error.message || 'Invalid API key. Please try again.'; - } - }); - - // === Theme Toggle Setup === - const themeToggle = document.getElementById('themeToggle'); - const body = document.body; - - let savedTheme = localStorage.getItem('theme'); - if (!savedTheme) { - savedTheme = 'light-mode'; - localStorage.setItem('theme', savedTheme); - } - body.classList.add(savedTheme); +// Load saved theme from localStorage +const savedTheme = localStorage.getItem('theme'); +if (savedTheme) { + body.className = savedTheme; themeToggle.textContent = savedTheme === 'dark-mode' ? '☀️' : '🌙'; +} + +themeToggle.addEventListener('click', () => { + if (body.classList.contains('dark-mode')) { + body.classList.replace('dark-mode', 'light-mode'); + themeToggle.textContent = '🌙'; + localStorage.setItem('theme', 'light-mode'); + } else { + body.classList.replace('light-mode', 'dark-mode'); + themeToggle.textContent = '☀️'; + localStorage.setItem('theme', 'dark-mode'); + } +}); - themeToggle.addEventListener('click', () => { - if (body.classList.contains('dark-mode')) { - body.classList.remove('dark-mode'); - body.classList.add('light-mode'); - localStorage.setItem('theme', 'light-mode'); - themeToggle.textContent = '🌙'; - } else { - body.classList.remove('light-mode'); - body.classList.add('dark-mode'); - localStorage.setItem('theme', 'dark-mode'); - themeToggle.textContent = '☀️'; - } - }); +// Save API key +const saveBtn = document.getElementById('saveApiKey'); +const input = document.getElementById('apiKeyInput'); + +saveBtn.addEventListener('click', () => { + const key = input.value.trim(); + if (key) { + chrome.storage.local.set({ groqApiKey: key }, () => { + alert('API key saved!'); + }); + } else { + alert('Please enter a valid API key.'); + } });