Tampermonkey to access a JSON call/ URL on a page?

Viewed 13791

I have a page index.html which calls an external URL. This external URL is a JSON endpoint. In other words, I see two resources when I open dev tools (with F12): index.html and myJSONEndpoint.

I want to be able to grab that JSON each time I load index.html and do something with it.

Would Greasemonkey or Tampermonkey be able to achieve this?

Page example:

<!doctype html>
<html>
<head>
 <title>Weather</title>
<script>
   var xmlhttp = new XMLHttpRequest();
   xmlhttp.onreadystatechange = function() {
      if (this.readyState == 4 && this.status == 200) {
             var myObj = JSON.parse(this.responseText);
        }
 };
xmlhttp.open("GET", "https://api.weather.gov/points/39.7456,-97.0892", true);
xmlhttp.send();
</script>
</head>
<body>
  <p>Page Loaded...</p>
</body>
</html>

When I load that page, two requests appear in dev-tools. Base index page and the JSON request.

I want to grab the JSON content and push it onto the DOM. The User can then copy/paste from there.
Create a new <div> and then stick the contents in there?

0 Answers
Related