In this code, I'm modifying all outgoing links. I've added "?" successfully. I also want to add a dynamic string which I'm fetching from a URL but have failed. Here's my code:
fetch('https://httpbin.org/encoding/utf8')
  .then((response) => {
    return response.text();
  })
  .then((text) => {
    document.getElementById("MyFetchedString").innerHTML = text.slice(0, 10);
      });
document.addEventListener( "DOMContentLoaded", modify_outbound_links);
function modify_outbound_links(){
    anchors = document.getElementsByTagName('a');
    for (let i = 0; i < anchors.length; i++) {
        let p = anchors[i].href;
        if (p.indexOf('example.com') === -1) {
        //How do i append the fetchedText here? 
            anchors[i].href = p + (p.indexOf('?') != -1 ? "&" : "?") + 'FetchedText'; 
        }
    }
}
<!DOCTYPE html>
<html>
<head>
  <title>My Website</title>
  </head>
<body>
  <h2>My First Web Page</h2>
  <p>My First Paragraph.</p>
  Modify all outbound links.<br>
 <p><a href="https://google.com/">Google.com</a></p>
<p><a href="https://yahoo.com/">Yahoo.com</a></p>
<p><a href="https://example.com/">mydomain.com</a></p>
<p id="MyFetchedString"></p>
</body>
How do I append the fetchedText here:
anchors[i].href = p + (p.indexOf('?') != -1 ? "&" : "?") + '**I WANT THE FETCHED TEXT HERE**';
 
     
     
    