Skip to content

Instantly share code, notes, and snippets.

@qufighter
Created May 30, 2010 02:19
Show Gist options
  • Save qufighter/418707 to your computer and use it in GitHub Desktop.
Save qufighter/418707 to your computer and use it in GitHub Desktop.
Document Start Test Script available here http://userscripts.org/scripts/show/78045
// ==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);
@qufighter
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment