Created
August 10, 2026 16:00
-
-
Save ngocjohn/bcd2a0b836f1d1c1a46a4f336390437c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const getHa = () => document.querySelector('home-assistant'); | |
| const waitForDialogCreateCard = (ha, timeoutMs = 2000) => | |
| new Promise((resolve) => { | |
| const find = () => ha?.renderRoot?.querySelector('hui-dialog-create-card'); | |
| const existing = find(); | |
| if (existing) return resolve(existing); | |
| const done = (dcc) => { | |
| observer.disconnect(); | |
| clearTimeout(timer); | |
| resolve(dcc); | |
| }; | |
| const observer = new MutationObserver(() => { | |
| const dcc = find(); | |
| if (dcc) done(dcc); | |
| }); | |
| observer.observe(ha.renderRoot, { childList: true, subtree: true }); | |
| const timer = setTimeout(() => done(null), timeoutMs); | |
| }); | |
| const toggleExpandedPanels = (dcc, timeoutMs = 2000) => | |
| new Promise((resolve) => { | |
| const find = () => | |
| dcc?.renderRoot | |
| ?.querySelector('hui-card-picker') | |
| ?.shadowRoot.querySelectorAll('ha-expansion-panel'); | |
| const existing = find(); | |
| if (existing) return resolve(existing); | |
| const done = (panels) => { | |
| observer.disconnect(); | |
| clearTimeout(timer); | |
| resolve(panels); | |
| }; | |
| const observer = new MutationObserver(() => { | |
| const panels = find(); | |
| if (panels) done(panels); | |
| }); | |
| observer.observe(dcc.renderRoot, { childList: true, subtree: true }); | |
| const timer = setTimeout(() => done(null), timeoutMs); | |
| }); | |
| async function toggleCardTab() { | |
| const ha = getHa(); | |
| const dcc = await waitForDialogCreateCard(ha); | |
| if (dcc && dcc._currTab !== 'card') { | |
| dcc._currTab = 'card'; | |
| } | |
| setTimeout(async () => { | |
| if (dcc && dcc._currTab === 'card') { | |
| const panels = await toggleExpandedPanels(dcc); | |
| console.log(panels); | |
| if (panels) { | |
| Array.from(panels).forEach((p) => p.removeAttribute('expanded')); | |
| } | |
| } | |
| }, 0); | |
| } | |
| function initCardTab() { | |
| console.info('%cInit Change Create Card Dialog', 'color: lightgreen; font-style: italic'); | |
| window.addEventListener('show-dialog', (event) => { | |
| if (event.detail?.dialogTag !== 'hui-dialog-create-card') return; | |
| toggleCardTab(); | |
| }); | |
| } | |
| initCardTab(); |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
keep
favorite cards panelexpanded