Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save erikvold/656232 to your computer and use it in GitHub Desktop.
Save erikvold/656232 to your computer and use it in GitHub Desktop.
// ==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;}');
alert(document.readyState);
alert(!document.body || document.body.innerHTML);
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