Auto-deploy: 2026-06-02 18:48:35

This commit is contained in:
Hamza-Ayed
2026-06-02 18:48:35 +03:00
parent 6d4337bccf
commit 4bab69d2b1
2 changed files with 36 additions and 18 deletions

View File

@@ -294,13 +294,13 @@ function initDictation() {
}
}
// Listen to messages from the offscreen document via the background
// Listen to messages from the injected script
chrome.runtime.onMessage.addListener((message) => {
if (message.type === 'OFFSCREEN_RECORDING_RESULT') {
if (message.type === 'SPEECH_RESULT') {
interimTranscript = message.payload.interimText || '';
finalTranscript = message.payload.finalText || '';
resultArea.value = (finalTranscript + interimTranscript).trim();
} else if (message.type === 'OFFSCREEN_RECORDING_ERROR') {
} else if (message.type === 'SPEECH_ERROR') {
console.error('Speech recognition error', message.payload.error);
if (message.payload.error === 'not-allowed') {
statusEl.textContent = '❌ يرجى السماح للميكروفون من إعدادات المتصفح';
@@ -309,7 +309,7 @@ function initDictation() {
statusEl.textContent = '❌ خطأ: ' + message.payload.error;
}
stopRecording(false);
} else if (message.type === 'OFFSCREEN_RECORDING_END') {
} else if (message.type === 'SPEECH_END') {
if (isRecording) {
stopRecording(true);
}
@@ -355,19 +355,34 @@ function initDictation() {
iframe.style.left = '0';
iframe.style.width = '1px';
iframe.style.height = '1px';
iframe.style.opacity = '0';
iframe.style.opacity = '0.01';
iframe.style.pointerEvents = 'none';
iframe.style.zIndex = '-9999';
iframe.style.border = 'none';
iframe.setAttribute('allow', 'microphone');
document.body.appendChild(iframe);
// Relay messages from iframe to popup
window.addEventListener('message', (event) => {
if (event.data && event.data.type && event.data.type.startsWith('SPEECH_')) {
chrome.runtime.sendMessage(event.data);
}
});
// Listen for messages from popup to iframe
chrome.runtime.onMessage.addListener((msg, sender, sendResponse) => {
if (msg.type === 'START_RECORDING_FROM_POPUP' || msg.type === 'STOP_RECORDING_FROM_POPUP') {
iframe.contentWindow.postMessage(msg, '*');
sendResponse({ success: true });
}
});
}
},
args: [extensionUrl]
}).then(() => {
// Small delay to ensure iframe has loaded and registered listener
setTimeout(() => {
chrome.runtime.sendMessage({
chrome.tabs.sendMessage(activeTab.id, {
type: 'START_RECORDING_FROM_POPUP',
payload: { language: 'ar-SA' }
});