Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // function runs when body has loaded completely
- var times = 3; // the number of extra pages we will render
- 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)
- // this loop iterates over the links at the bottom of the page as url, and calls getAJAX(url) for each
- for(var i=0; i < times; i++){
- var url = document.querySelectorAll(`[class=fl][aria-label*="Page ${i + 2}"]`)[0].href;
- let request = new XMLHttpRequest(); // create request object
- request.open("GET", url); // direct the request to HTTP GET the url
- request.onreadystatechange = function () {
- if(request.readyState == 4 && request.status == 200){
- newHtml = request.responseText.match(/<body[^>]*>([\w|\W]*)<\/body>/im); // get innerHTML of <body> of new page as a string
- newpage = document.createElement('div'); // create a new DIV in which to render the responseText
- newpage.innerHTML = newHtml; // set DIV content to modified responseText
- document.body.appendChild(newpage); // append the new element to the page BODY
- }
- }
- request.send(null)
- alert(i);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement