title: Code working in browser console but not in tampermonkey
body: <p>I am trying to run the following block of code on <a href="https://lichess.org/uZIjh0SXxnt5" rel="nofollow noreferrer">https://lichess.org/uZIjh0SXxnt5</a>.</p>
  
  <pre><code>var x = document.getElementsByTagName("a");
  
  for(var i = 0; i &lt; x.length; i++) {
      if(x[i].href.includes("WaisKamal") &amp;&amp; x[i].classList.contains("user_link")) {
          x[i].innerHTML = '&lt;span class="title" data-title="GM" title="Grandmaster"&gt;GM&lt;/span&gt; ' + x[i].innerHTML;
      }
  
      if(x[i].href.includes("WaisKamal") &amp;&amp; x[i].classList.contains("text")) {
          x[i].innerHTML = '&lt;span class="title" data-title="GM" title="Grandmaster"&gt;GM&lt;/span&gt; ' + x[i].innerHTML;
          console.log(x[i]);
      }
  }
  </code></pre>
  
  <p>I am using tampermonkey to automate the process. When the page loads, the first if statement runs correctly, but not the second one. However, when I run the second one from the browser console, it works fine.</p>
  
  <p>Here is what the script does in more detail (I want to add those orange "GM"s):</p>
  
  <p><strong>Without the script</strong></p>
  
  <p><a href="https://i.stack.imgur.com/WIHCY.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WIHCY.png" alt="enter image description here"></a></p>
  
  <p><strong>With the script</strong></p>
  
  <p><a href="https://i.stack.imgur.com/5X72Q.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/5X72Q.png" alt="enter image description here"></a></p>
  
  <p><strong>What I want</strong></p>
  
  <p><a href="https://i.stack.imgur.com/DlCm4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/DlCm4.png" alt="enter image description here"></a></p>
  
  <p>I have checked <a href="https://stackoverflow.com/questions/23923992/code-from-bookmarklet-works-in-console-but-not-in-my-tampermonkey-script">this</a> but it didn't solve my problem.</p>
  
  <p>Any help? Thanks in advance.</p>