Advertisement
Guest User

Untitled

a guest
Apr 24th, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. // function runs when body has loaded completely
  2. var times = 3; // the number of extra pages we will render
  3. var newpage; // a variable to represent the <div> in which each new page will be created. Defined here so it is not re-defined multiple times (inefficient)
  4.  
  5. // this loop iterates over the links at the bottom of the page as url, and calls getAJAX(url) for each
  6. for(var i=0; i < times; i++){
  7. var url = document.querySelectorAll(`[class=fl][aria-label*="Page ${i + 2}"]`)[0].href;
  8. let request = new XMLHttpRequest(); // create request object
  9. request.open("GET", url); // direct the request to HTTP GET the url
  10. request.onreadystatechange = function () {
  11. if(request.readyState == 4 && request.status == 200){
  12. newHtml = request.responseText.match(/<body[^>]*>([\w|\W]*)<\/body>/im); // get innerHTML of <body> of new page as a string
  13. newpage = document.createElement('div'); // create a new DIV in which to render the responseText
  14. newpage.innerHTML = newHtml; // set DIV content to modified responseText
  15. document.body.appendChild(newpage); // append the new element to the page BODY
  16. alert("appended once");
  17. }
  18. }
  19. request.send(null)
  20. alert(i);
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement