<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Any way to access overall DOM?]]></title><description><![CDATA[<p dir="auto">Hi,</p>
<p dir="auto">I’m writing a module that changes the background colour dynamically.  As a consequence of this, I’d like the text to be as readable as possible.</p>
<p dir="auto">The difficulty is that although I’ve found a way to dynamically determine the optimal text colour for the current background colour, I have no way to push other modules to use it.  Ideally I’d like to modify the --color-text variable dynamically.  But I can’t see any way to do this.</p>
<p dir="auto">Am I overlooking a simple answer?</p>
]]></description><link>https://forum.magicmirror.builders/topic/19007/any-way-to-access-overall-dom</link><generator>RSS for Node</generator><lastBuildDate>Sat, 18 Apr 2026 11:00:45 GMT</lastBuildDate><atom:link href="https://forum.magicmirror.builders/topic/19007.rss" rel="self" type="application/rss+xml"/><pubDate>Sat, 21 Sep 2024 17:44:05 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Any way to access overall DOM? on Sat, 21 Sep 2024 20:31:05 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mystara" aria-label="Profile: Mystara">@<bdi>Mystara</bdi></a><br />
Not tested, only with my brain, so just idea.</p>
<ol>
<li>Get all the DOMs which has textContent.</li>
</ol>
<pre><code class="language-javascript">const els = document.querySelectorAll('*')
for (let i = 0; i &lt; els.length; i++) {
  const el = els[i]
  const children = el.childNodes
  let hasText = false
  for (let j = children.length; j--) {
    if (children[j].nodeType === 3 &amp;&amp; children[j].nodeValue.trim().length) {
      hasText = true
      break
    }
  }
  if (hasText) {
    //This element has text content
  }
}
</code></pre>
<ol start="2">
<li>If it and its ancestors don’t have a background, apply your solution.</li>
</ol>
<pre><code class="language-javascript">// assume that already know target element
let withoutBackground = true
let node = targetElement
while (node.parentElement) { // until document
  const styles = window.getComputedStyle(node)
  if (styles.backgroundColor === 'transparent' || ... ) { // Maybe backgroundImage should be checked too.
    // node has no background, so check the parent
    node = node.parentElement
  } else {
    withoutBackground = false
    break
  }
}
if (withoutBackground)  {
  // the target element has no its own background. So you can apply your solution.
}
</code></pre>
<p dir="auto">To improve : a caching strategy for a once checked node to skip would be better.)</p>
<p dir="auto">However, I’m not too fond of this approach,</p>
<ol>
<li><code>getComputedStyle</code> is very expensive</li>
<li>Rather, it would be better to propose a <code>theme</code> style guide as MagicMirror’s default coding rules.</li>
</ol>
]]></description><link>https://forum.magicmirror.builders/post/119956</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/119956</guid><dc:creator><![CDATA[MMRIZE]]></dc:creator><pubDate>Sat, 21 Sep 2024 20:31:05 GMT</pubDate></item><item><title><![CDATA[Reply to Any way to access overall DOM? on Sat, 21 Sep 2024 18:41:18 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mystara" aria-label="Profile: Mystara">@<bdi>Mystara</bdi></a> maybe</p>
<p dir="auto">get computed style</p>
<p dir="auto">see</p>
<p dir="auto"><a href="https://stackoverflow.com/questions/41725725/access-css-variable-from-javascript" target="_blank" rel="noopener noreferrer nofollow ugc">https://stackoverflow.com/questions/41725725/access-css-variable-from-javascript</a></p>
]]></description><link>https://forum.magicmirror.builders/post/119955</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/119955</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sat, 21 Sep 2024 18:41:18 GMT</pubDate></item><item><title><![CDATA[Reply to Any way to access overall DOM? on Sun, 06 Oct 2024 12:10:51 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="/user/mystara" aria-label="Profile: Mystara">@<bdi>Mystara</bdi></a> the dom is  document in js</p>
<p dir="auto">i don’t think the variables are exposed in the dom, they are used to calculate on load as i understand it.</p>
<p dir="auto">you can see the text rep of the dom in the developers window elements tab</p>
]]></description><link>https://forum.magicmirror.builders/post/119952</link><guid isPermaLink="true">https://forum.magicmirror.builders/post/119952</guid><dc:creator><![CDATA[sdetweil]]></dc:creator><pubDate>Sun, 06 Oct 2024 12:10:51 GMT</pubDate></item></channel></rss>