diff --git a/frontend/overlays/src/helpers.ts b/frontend/overlays/src/helpers.ts index c569021db..e79e9e568 100644 --- a/frontend/overlays/src/helpers.ts +++ b/frontend/overlays/src/helpers.ts @@ -76,3 +76,33 @@ export function normalizeDisplayName(displayName: string, userName: string): str return userName } + +export function loadEruda() { + const url = new URL(location.href) + const isDebug = url.searchParams.get('debug') + if (!isDebug) return + + const script = document.createElement('script') + script.src = 'https://cdn.jsdelivr.net/npm/eruda@3.4.3/eruda.min.js' + + script.onload = () => { + if (!window.eruda) return + window.eruda.init() + window.eruda.show() + } + + script.onerror = () => { + const error = document.createElement('div') + error.textContent = 'Failed to load eruda' + Object.assign(error.style, { + background: 'red', + color: 'white', + textAlign: 'center', + fontWeight: 'bold', + padding: '10px 0', + }) + document.body.prepend(error) + } + + document.head.append(script) +} diff --git a/frontend/overlays/src/main.ts b/frontend/overlays/src/main.ts index f68b214b6..381245251 100644 --- a/frontend/overlays/src/main.ts +++ b/frontend/overlays/src/main.ts @@ -4,8 +4,9 @@ import { createApp } from 'vue' import { urqlClientOptions } from '@/plugins/urql.ts' import MainApp from './app.vue' -import './style.css' import { router } from './plugins/router.js' +import { loadEruda } from './helpers.js' +import './style.css' const app = createApp(MainApp) @@ -13,6 +14,9 @@ app.use(router).use(urql, urqlClientOptions) app.mount('#app') +// eruda devtools +loadEruda() + // refresh the page when new version comes document.body.addEventListener('plugin_web_update_notice', () => { window.location.reload() diff --git a/frontend/overlays/src/pages/alerts.vue b/frontend/overlays/src/pages/alerts.vue index a8368f3bc..50146eba0 100644 --- a/frontend/overlays/src/pages/alerts.vue +++ b/frontend/overlays/src/pages/alerts.vue @@ -6,12 +6,6 @@ import { useRoute } from 'vue-router' import { openApi } from '@/api.ts' import { generateSocketUrlWithParams } from '@/helpers.js' -declare global { - interface Window { - webkitAudioContext: typeof AudioContext - } -} - const queue = ref([]) const currentAudioBuffer = ref(null) diff --git a/frontend/overlays/src/vite-env.d.ts b/frontend/overlays/src/vite-env.d.ts index de503b58b..8ace1cc8d 100644 --- a/frontend/overlays/src/vite-env.d.ts +++ b/frontend/overlays/src/vite-env.d.ts @@ -1,11 +1,13 @@ /// declare global { - interface Window { - webkitAudioContext: typeof AudioContext - } + interface Window { + eruda: any + } } /// /// declare module '*.vue'; + +export {}