🐛 Fix: Add microphone permission to manifest, add direct fetch fallback for Gemini in content.js
This commit is contained in:
@@ -373,6 +373,9 @@
|
|||||||
async function processWithGemini(text) {
|
async function processWithGemini(text) {
|
||||||
isGeminiProcessing = true;
|
isGeminiProcessing = true;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Try via background service worker first
|
||||||
|
let processedText = null;
|
||||||
try {
|
try {
|
||||||
const response = await chrome.runtime.sendMessage({
|
const response = await chrome.runtime.sendMessage({
|
||||||
type: 'GEMINI_PROCESS_VOICE',
|
type: 'GEMINI_PROCESS_VOICE',
|
||||||
@@ -385,11 +388,71 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (response && response.success) {
|
if (response && response.success) {
|
||||||
const processedText = response.data.text;
|
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);
|
insertTextIntoClaude(processedText);
|
||||||
showStatus('done', '✅ تمت المعالجة بواسطة Gemini');
|
showStatus('done', '✅ تمت المعالجة بواسطة Gemini');
|
||||||
} else {
|
} else {
|
||||||
// Fallback: insert original text
|
|
||||||
insertTextIntoClaude(text);
|
insertTextIntoClaude(text);
|
||||||
showStatus('done', '✅ تم الإدراج (بدون معالجة)');
|
showStatus('done', '✅ تم الإدراج (بدون معالجة)');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
"storage",
|
"storage",
|
||||||
"activeTab",
|
"activeTab",
|
||||||
"scripting",
|
"scripting",
|
||||||
"clipboardWrite"
|
"clipboardWrite",
|
||||||
|
"microphone"
|
||||||
],
|
],
|
||||||
"host_permissions": [
|
"host_permissions": [
|
||||||
"https://www.linkedin.com/*",
|
"https://www.linkedin.com/*",
|
||||||
|
|||||||
Reference in New Issue
Block a user