-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
1 parent
945ea0b
commit 0b0804e
Showing
1 changed file
with
88 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
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); | ||
|