From 873b965f90f724e67729095c81e8b3db5daa55b4 Mon Sep 17 00:00:00 2001 From: Hamza-Ayed Date: Tue, 2 Jun 2026 17:55:16 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fix:=20Add=20microphone=20permis?= =?UTF-8?q?sion=20to=20manifest,=20add=20direct=20fetch=20fallback=20for?= =?UTF-8?q?=20Gemini=20in=20content.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- claude-arabic-voice/content.js | 87 +++++++++++++++++++++++++++++----- manifest.json | 3 +- 2 files changed, 77 insertions(+), 13 deletions(-) diff --git a/claude-arabic-voice/content.js b/claude-arabic-voice/content.js index 0b53aa5..c1db068 100644 --- a/claude-arabic-voice/content.js +++ b/claude-arabic-voice/content.js @@ -374,22 +374,85 @@ isGeminiProcessing = true; try { - const response = await chrome.runtime.sendMessage({ - type: 'GEMINI_PROCESS_VOICE', - payload: { - apiKey: settings.geminiApiKey, - model: settings.geminiModel, - text: text, - language: settings.language - } - }); + // Try via background service worker first + let processedText = null; + try { + const response = await chrome.runtime.sendMessage({ + type: 'GEMINI_PROCESS_VOICE', + payload: { + apiKey: settings.geminiApiKey, + model: settings.geminiModel, + text: text, + language: settings.language + } + }); - if (response && response.success) { - const processedText = response.data.text; + if (response && response.success) { + processedText = response.data.text; + } else { + console.warn('[ClaudeVoice] Background response not successful:', response?.error); + } + } catch (bgErr) { + console.warn('[ClaudeVoice] Background message failed, trying direct fetch:', bgErr); + } + + // Fallback: direct fetch to server + if (!processedText) { + try { + const isArabic = /[\u0600-\u06FF]/.test(text); + const langName = isArabic ? 'Arabic' : 'the detected language'; + + const prompt = `You are a text refinement assistant. Your task is to: + +1. Correct any speech recognition errors in the following text +2. Fix punctuation, capitalization, and formatting +3. Keep the original meaning and content intact +4. Do NOT add any new information or commentary +5. Return ONLY the corrected text, nothing else + +The text is in ${langName}. Preserve the original language. + +TEXT TO REFINE: +${text} + +CORRECTED TEXT:`; + + const directResponse = await fetch('https://cv.intaleqapp.com/cv/server/generate_cv.php', { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + action: 'generateText', + apiKey: settings.geminiApiKey, + prompt: prompt + }) + }); + + if (directResponse.ok) { + const rawText = await directResponse.text(); + let data; + try { + data = JSON.parse(rawText); + } catch (e) { + data = rawText; + } + + if (data && data.candidates && data.candidates[0]) { + processedText = data.candidates[0].content?.parts?.[0]?.text; + } else if (typeof data === 'string') { + processedText = data; + } + } else { + console.warn('[ClaudeVoice] Direct fetch failed:', directResponse.status); + } + } catch (fetchErr) { + console.warn('[ClaudeVoice] Direct fetch error:', fetchErr); + } + } + + if (processedText) { insertTextIntoClaude(processedText); showStatus('done', '✅ تمت المعالجة بواسطة Gemini'); } else { - // Fallback: insert original text insertTextIntoClaude(text); showStatus('done', '✅ تم الإدراج (بدون معالجة)'); } diff --git a/manifest.json b/manifest.json index 8923df2..100253b 100644 --- a/manifest.json +++ b/manifest.json @@ -7,7 +7,8 @@ "storage", "activeTab", "scripting", - "clipboardWrite" + "clipboardWrite", + "microphone" ], "host_permissions": [ "https://www.linkedin.com/*",