Upload files to "kronic-chat/js"
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
/* Kronic compact room layout. Retain every existing audio control and listener. */
|
||||
(() => {
|
||||
function init() {
|
||||
const sidebar = document.getElementById('connectionPanel');
|
||||
const header = document.querySelector('.topbar');
|
||||
if (!sidebar || !header || document.getElementById('kronicVoiceTop')) return;
|
||||
|
||||
const connection = sidebar.querySelector('.panel-section:not(.audio-settings-section)');
|
||||
const top = document.createElement('div');
|
||||
top.id = 'kronicVoiceTop';
|
||||
top.className = 'kronic-voice-top';
|
||||
header.insertBefore(top, header.querySelector('.topbar-tools') || null);
|
||||
if (connection) top.append(connection);
|
||||
|
||||
// Three independent popups use the original details elements, not clones.
|
||||
const names = ['voice', 'noise', 'spatial'];
|
||||
const groups = [...sidebar.querySelectorAll('.audio-setting-group.audio-collapsible')];
|
||||
const popups = {};
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
const panel = document.createElement('section');
|
||||
panel.className = 'kronic-audio-popup';
|
||||
panel.dataset.audioPopup = names[i];
|
||||
panel.hidden = true;
|
||||
panel.setAttribute('role', 'dialog');
|
||||
panel.setAttribute('aria-label', names[i] + ' audio settings');
|
||||
const close = document.createElement('button');
|
||||
close.className = 'kronic-audio-close';
|
||||
close.type = 'button';
|
||||
close.textContent = '×';
|
||||
close.setAttribute('aria-label', 'Close audio settings');
|
||||
close.addEventListener('click', () => hideAll());
|
||||
panel.append(close);
|
||||
if (groups[i]) {
|
||||
groups[i].open = true;
|
||||
panel.append(groups[i]);
|
||||
}
|
||||
// Noise suppression has Apply and restart-hint elements in the same source section.
|
||||
if (names[i] === 'noise') {
|
||||
const section = sidebar.querySelector('.audio-settings-section');
|
||||
// Keep external controls that are siblings of the noise group near their original section.
|
||||
// Existing handlers remain attached to the original DOM nodes.
|
||||
}
|
||||
document.body.append(panel);
|
||||
popups[names[i]] = panel;
|
||||
}
|
||||
sidebar.classList.add('kronic-parked-sidebar');
|
||||
document.body.append(sidebar);
|
||||
|
||||
function hideAll() {
|
||||
Object.values(popups).forEach(panel => panel.hidden = true);
|
||||
window.parent?.postMessage({type:'KRONIC_ROOM_UI_PANEL', action:'closed'}, location.origin);
|
||||
}
|
||||
window.addEventListener('message', event => {
|
||||
if (event.origin !== location.origin || event.source !== window.parent) return;
|
||||
const message = event.data;
|
||||
if (message?.type !== 'KRONIC_ROOM_UI') return;
|
||||
if (message.action === 'close-audio') hideAll();
|
||||
else if (typeof message.action === 'string' && message.action.startsWith('open-audio-')) {
|
||||
const target = message.action.slice('open-audio-'.length);
|
||||
Object.entries(popups).forEach(([name,panel]) => panel.hidden = name !== target);
|
||||
if (popups[target]) popups[target].scrollTop = 0;
|
||||
} else if (message.action === 'mute') {
|
||||
document.getElementById('muteBtn')?.click();
|
||||
} else if (message.action === 'leave') {
|
||||
document.getElementById('leaveBtn')?.click();
|
||||
}
|
||||
});
|
||||
document.addEventListener('keydown', event => { if (event.key === 'Escape') hideAll(); });
|
||||
const state = document.getElementById('statusBar');
|
||||
const publish = () => {
|
||||
if (window.parent !== window) window.parent.postMessage({
|
||||
type:'KRONIC_ROOM_UI_STATUS',label:state?.textContent?.trim() || 'Not connected'
|
||||
},location.origin);
|
||||
};
|
||||
if (state) new MutationObserver(publish).observe(state, {childList:true,subtree:true,characterData:true});
|
||||
publish();
|
||||
}
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init, {once:true});
|
||||
else init();
|
||||
})();
|
||||
Reference in New Issue
Block a user