Created
May 30, 2010 02:19
-
-
Save qufighter/418707 to your computer and use it in GitHub Desktop.
Document Start Test Script available here http://userscripts.org/scripts/show/78045
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Document Start Test | |
// @namespace vidzbigger.com | |
// @description This scrip tests document-start | |
// @include http://* | |
// @run-at document-start | |
// ==/UserScript== | |
GM_addStyle('body{display:none;}'); | |
var isDocumentStart = (document.body==null); | |
function onLoaded(){ | |
document.body.appendChild(document.createTextNode('Code that executes at Document Load')); | |
GM_addStyle('body{display:block;}'); | |
} | |
function onDomNodeInserted(n){ | |
console.log(n.relatedNode); | |
} | |
if( isDocumentStart ){ | |
alert(' Hello! You are now running at document start! '); | |
document.addEventListener('DOMNodeInserted',onDomNodeInserted,true); | |
}else{ | |
alert(' Hello! Script is running at domContentLoaded ' ); | |
} | |
document.addEventListener('DOMContentLoaded',onLoaded,true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note that the old b89971 revision is BAD because it simply calls the onDomContentLoaded() function when not running at document start - this is bad because it will break fastback functionality since it will end up getting called twice.