I'm trying to use $(document).ready(function() to get the page to fully load before using the ajax but for some reason it's not working properly. I am only able to get only part of the page, because it does not wait for it to fully load before getting the content.
Which part of the code can I fix to fix this?
// ==UserScript==
// @name test1
// @namespace John Galt
// @description Basic Google Hello
// @match *://www.google.com/*
// @version 1
// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js
// @grant GM_xmlhttpRequest
// ==/UserScript==
$(document).ready(function(){
GM_xmlhttpRequest ( {
method: "GET",
url: "http://www.fictionpress.com/",
onload: function (response) {
var parser = new DOMParser ();
var doc = parser.parseFromString (response.responseText, "text/html");
var theString = new XMLSerializer().serializeToString(doc);
document.write(theString);
},
onerror: function (e) {
console.error ('**** error ', e);
},
onabort: function (e) {
console.error ('**** abort ', e);
},
ontimeout: function (e) {
console.error ('**** timeout ', e);
}
} );
});
You can add an option:
// @run-at document-end. That says Tampermonkey that you're need to wait full page loading.Full list of the options can be found here.