window.seemgen = { injectCssFile: function (href) { let existing = document.getElementById("seemgen-css"); if (existing) existing.remove(); let link = document.createElement("link"); link.rel = "stylesheet"; link.href = href; link.id = "seemgen-css"; document.head.appendChild(link); } }; window.getUserLanguage = () => { return navigator.language || navigator.userLanguage || "en"; }; window.playAudio = (audioDataUrl) => { const audio = document.getElementById('audioPlayer'); audio.src = audioDataUrl; audio.style.display = 'block'; audio.play(); }; window.initHints = () => { const targets = document.querySelectorAll('[data-hint]'); if (!targets.length) { console.warn("No elements with data-hint found."); } targets.forEach(target => { const hintText = target.getAttribute('data-hint'); console.log("---------------HINT---------------------", hintText); const hint = document.createElement('div'); hint.className = 'floating-hint'; hint.innerText = hintText; document.body.appendChild(hint); const showHint = () => { const rect = target.getBoundingClientRect(); hint.style.left = `${rect.left + window.scrollX + rect.width + 8}px`; hint.style.top = `${rect.top + window.scrollY}px`; hint.style.opacity = '1'; setTimeout(() => hint.style.opacity = '0', 3000); }; setInterval(showHint, 10000); }); }; window.initVoiceRecorder = function (dotnetMethodName) { console.log("initVoiceRecorder called"); const recButton = document.getElementById("recButton"); const stopButton = document.getElementById("stopButton"); const recText = document.getElementById("recordingText"); if (!recButton || !stopButton || !recText) { console.warn("Voice recorder elements not found"); return; } let mediaRecorder; let audioChunks = []; navigator.permissions.query({ name: 'microphone' }).then(function (result) { if (result.state == 'granted') { } else if (result.state == 'prompt') { } else if (result.state == 'denied') { } result.onchange = function () { }; }); // Define globally so HTML can access it window.startRecording = async function () { recButton.hidden = true; stopButton.hidden = false; recText.textContent = "recording..."; const stream = await navigator.mediaDevices.getUserMedia({ audio: true }); mediaRecorder = new MediaRecorder(stream); mediaRecorder.ondataavailable = event => audioChunks.push(event.data); mediaRecorder.onstop = () => { const audioBlob = new Blob(audioChunks, { type: 'audio/wav' }); audioChunks = []; const reader = new FileReader(); reader.onload = () => { const base64Audio = reader.result.split(',')[1]; DotNet.invokeMethodAsync('BLAIzor', dotnetMethodName, base64Audio, window.sessionId); }; reader.readAsDataURL(audioBlob); }; mediaRecorder.start(); }; window.stopRecording = function () { if (mediaRecorder) { mediaRecorder.stop(); mediaRecorder.stream.getTracks().forEach(track => track.stop()); stopButton.hidden = true; recButton.hidden = false; recText.textContent = ""; } }; };