Skip to content

Commit

Permalink
Create update_more_info.js (#96)
Browse files Browse the repository at this point in the history
in an effort to isolate the update more-info and be able to optimize that more easily, this is a standalone version
  • Loading branch information
Mariusthvdb authored Jun 28, 2023
1 parent 945ea0b commit 0b0804e
Showing 1 changed file with 88 additions and 0 deletions.
88 changes: 88 additions & 0 deletions update_more_info.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
const Name = "Update more-info";
const Version = "20230628";
const Description = "standalone";
const Url = "https://github.com/Mariusthvdb/custom-ui";

// Log information about the custom-ui component
console.info(
`%c ${Name} \n%c Version ${Version} ${Description}`,
"color: gold; font-weight: bold; background: black",
"color: white; font-weight: bold; background: steelblue"
);

// Update the more-info dialog to hide certain attributes based on custom logic
function updateMoreInfo(ev) {
if (!ev.detail.expanded) return;
const moreInfoInfo = document
.querySelector("home-assistant")
.shadowRoot.querySelector("ha-more-info-dialog")
.shadowRoot.querySelector("ha-dialog")
.getElementsByClassName("content")[0]
.querySelector("ha-more-info-info");

try {
let t;
{
let moreInfoNodeName;
const contentChild = moreInfoInfo.shadowRoot.querySelector(
"more-info-content"
).childNodes;
for (const nodeItem of contentChild) {
if (nodeItem.nodeName.toLowerCase().startsWith("more-info-")) {
moreInfoNodeName = nodeItem.nodeName.toLowerCase();
break;
}
}
if (moreInfoNodeName == "more-info-group") {
let moreInfoNestedNodeName;
const contentChildNested =
moreInfoInfo.shadowRoot
.querySelector("more-info-group")
.shadowRoot.childNodes;
for (const nodeItemNested of contentChildNested) {
if (
nodeItemNested.nodeName.toLowerCase().startsWith("more-info-")
) {
moreInfoNestedNodeName = nodeItemNested.nodeName.toLowerCase();
break;
}
}
t = moreInfoInfo.shadowRoot
.querySelector("more-info-group")
.shadowRoot.querySelector(moreInfoNestedNodeName)
.shadowRoot.querySelector("ha-attributes")
.shadowRoot.querySelectorAll(".data-entry");
} else {
t = moreInfoInfo.shadowRoot
.querySelector(moreInfoNodeName)
.shadowRoot.querySelector("ha-attributes")
.shadowRoot.querySelectorAll(".data-entry");
}
}
if (t.length) {
let e;
for (const node of t) {
const o = node.getElementsByClassName("key")[0];
if (o.innerText.toLowerCase().trim() == "hide attributes") {
e = o.parentNode
.getElementsByClassName("value")[0]
.innerText.split(",")
.map((item) => item.replace("_", " ").trim());
e.push("hide attributes");
}
}
for (const node of t) {
const o = node.getElementsByClassName("key")[0];
if (
e.includes(o.innerText.toLowerCase().trim()) ||
e.includes("all")
) {
o.parentNode.style.display = "none";
}
}
}
} catch (err) {}
}

window.addEventListener("expanded-changed", updateMoreInfo);

0 comments on commit 0b0804e

Please sign in to comment.