Auto-deploy: 2026-06-02 18:39:04

This commit is contained in:
Hamza-Ayed
2026-06-02 18:39:04 +03:00
parent 8ebbedad83
commit 979a5bbdae
5 changed files with 186 additions and 63 deletions

View File

@@ -318,24 +318,55 @@ function initDictation() {
if (isRecording) {
stopRecording(true);
} else {
isRecording = true;
micBtn.style.background = 'linear-gradient(135deg, #ff4d6d, #c9184a)';
micBtn.innerHTML = '🔴';
statusEl.textContent = 'جارٍ الاستماع... اضغط للإيقاف';
finalTranscript = '';
interimTranscript = '';
resultArea.value = '';
copyBtn.style.display = 'none';
chrome.runtime.sendMessage({
type: 'START_RECORDING_FROM_POPUP',
payload: { language: 'ar-SA' }
}, (response) => {
if (!response || !response.success) {
console.error('Failed to start recording', response);
statusEl.textContent = '❌ فشل بدء التسجيل';
stopRecording(false);
// First, get the active tab
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
const activeTab = tabs[0];
// Cannot inject into chrome:// or chrome-extension:// pages
if (!activeTab || !activeTab.url || activeTab.url.startsWith('chrome://') || activeTab.url.startsWith('chrome-extension://') || activeTab.url.startsWith('edge://')) {
statusEl.textContent = '❌ يرجى فتح موقع عادي أولاً (مثل جوجل أو لينكدإن)';
return;
}
isRecording = true;
micBtn.style.background = 'linear-gradient(135deg, #ff4d6d, #c9184a)';
micBtn.innerHTML = '🔴';
statusEl.textContent = 'جارٍ الاستماع... اضغط للإيقاف';
finalTranscript = '';
interimTranscript = '';
resultArea.value = '';
copyBtn.style.display = 'none';
const extensionUrl = chrome.runtime.getURL('speech.html');
chrome.scripting.executeScript({
target: { tabId: activeTab.id },
func: (url) => {
let iframe = document.getElementById('lja-dictation-frame');
if (!iframe) {
iframe = document.createElement('iframe');
iframe.id = 'lja-dictation-frame';
iframe.src = url;
iframe.style.display = 'none';
// Allow microphone explicitly if needed
iframe.setAttribute('allow', 'microphone');
document.body.appendChild(iframe);
}
},
args: [extensionUrl]
}).then(() => {
// Small delay to ensure iframe has loaded and registered listener
setTimeout(() => {
chrome.runtime.sendMessage({
type: 'START_RECORDING_FROM_POPUP',
payload: { language: 'ar-SA' }
});
}, 500);
}).catch(err => {
console.error('Failed to inject iframe:', err);
statusEl.textContent = '❌ فشل الاتصال بالصفحة الحالية';
stopRecording(false);
});
});
}
});