javascript - How to get a Greasemonkey script to run both at @run-at document-start AND at @run-at document-end? -


For my Grayscenky script, a part of the code that should be played before the page is loaded ( @ Run-document-start ) and the second part of the code should be run after the document ( @ run-at document-end ). Is this possible?

  • The first part of running the script
  • The page is full, the document is ready
  • The second part of running the script

    I do not use jQuery for this.

    I tried the onload event but it was not working. I think the event can not be added if the document is not yet?

      window.document.onload = function (e) {alert ("document.onload"); }   

    You want the event to be DOMContentLoaded . In addition, it is not how to use the load event.

    Here is a complete script that shows the various firing times:

      // = = UserScript == // @name_ Show the page Start the event time / Include / @http: //your_SERVER.COM/YOUR_PATH/* // run-in document-start // ==/userscript == console.log ("==> script start.", New date ( )); // Part of a portion of 1 script goes here Console.log ("==> First part of running the script.", New Date ()); Document.addEventListener ("DOMContentLoaded", DOM_ContentReady); Window.addEventListener ("Loaded", Page Loaded Fully); The function goes to DOM_ContentReady () {// script two part 2 here. // This is equal to "run-in document-and console.log (" ==> second part of running script. ", New date ()); } Function Page Fully Loaded () {console.log ("==> Page is fully loaded, including images.", New Date ()); } Console.log ("==> Script End.", New Date ());   

    Specific results:

      "==> Start the script." 2014-10-09T01: 53: 49.323Z "==" gt; The first part of running the script '2014-10-09T01: 53: 49.323Z "==> Script End." 2014-10-09T01: 53: 49.323Z "==" gt; The second part of running the script. 2014-10-09T01: 53: 49.385Z "==> The page is completely full, including images." 2014-10-09T01: 53: 49.487Z    

  • Comments

    Popular posts from this blog

    php - PDO bindParam() fatal error -

    logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

    java - Why my included JSP file won't get processed correctly? -