From 08fa8c28f42c797f24b3bb912d117ad54f3dbdda Mon Sep 17 00:00:00 2001 From: John Livingston Date: Wed, 3 Apr 2024 15:06:18 +0200 Subject: [PATCH] Dirty hack to prevent some click event to default to href=# --- client/utils/conversejs.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/client/utils/conversejs.ts b/client/utils/conversejs.ts index 02bf0ad0..c2856db7 100644 --- a/client/utils/conversejs.ts +++ b/client/utils/conversejs.ts @@ -138,6 +138,23 @@ async function displayConverseJS ( converseRoot.classList.add('theme-peertube') container.append(converseRoot) + converseRoot.addEventListener('click', ev => { + // For some reason, there are some buttons in ConverseJS that are not working properly. + // When clicked, it does not prevent the default, so it try to open href="#". + // We will catch such clicks in converse-root, and prevent default! + if (!ev.target) { return } + + const a: HTMLAnchorElement | null = ('tagName' in ev.target) && ev.target.tagName === 'A' + ? ev.target as HTMLAnchorElement + : (ev.target as HTMLElement).closest('a') + + if (!a) { return } + if (a.getAttribute('href') !== '#') { return } + + console.log('[peertube-plugin-livechat] intercepting a click on href=# in converse root, canceling the event.') + ev.preventDefault() + }) + const authHeader = peertubeHelpers.getAuthHeader() const response = await fetch(