Hi, all!
If there’s anyone else like me, extremely annoyed by the fact that when you open an automation or a script, all actions are expanded and take up a huge amount of space on the page, so much so that if you have many actions it becomes very hard to follow them, here is a script I made, maybe it helps.
You can use the script below in a browser add‑on that injects JavaScript into the desired page.
I personally use Violentmonkey, and it works perfectly. Good luck
Updated 1.6 - If the URL has not been changed, do nothing
// ==UserScript==
// @name Home Assistant - Collapse All Actions (Once per URL)
// @version 1.6
// @description Collapse all automation & script actions once per editor URL
// @match http://192.168.0.102:8123/*
// @grant none
// ==/UserScript==
(function () {
'use strict';
let lastProcessedPath = null;
function isAllowedEditor() {
const p = location.pathname;
return (
p.startsWith('/config/automation/edit/') ||
p.startsWith('/config/script/edit/')
);
}
function collapseAllActionsOnce() {
const currentPath = location.pathname;
if (currentPath === lastProcessedPath) return;
if (!isAllowedEditor()) return;
lastProcessedPath = currentPath;
function findInShadows(root) {
root.querySelectorAll('*').forEach(el => {
if (
el.tagName === 'HA-AUTOMATION-ROW' &&
el.hasAttribute('building-block') &&
!el.hasAttribute('collapsed') &&
el.shadowRoot
) {
const expandButton =
el.shadowRoot.querySelector('ha-icon-button.expand-button');
if (expandButton) {
expandButton.click();
}
}
if (el.shadowRoot) {
findInShadows(el.shadowRoot);
}
});
}
setTimeout(() => findInShadows(document), 800);
}
setTimeout(collapseAllActionsOnce, 1500);
const push = history.pushState;
const replace = history.replaceState;
history.pushState = function () {
push.apply(this, arguments);
setTimeout(collapseAllActionsOnce, 500);
};
history.replaceState = function () {
replace.apply(this, arguments);
setTimeout(collapseAllActionsOnce, 500);
};
window.addEventListener('popstate', () => {
setTimeout(collapseAllActionsOnce, 500);
});
})();

