Skip to content

Instantly share code, notes, and snippets.

@pupi1985
Last active November 18, 2016 17:21
Show Gist options
  • Select an option

  • Save pupi1985/e463b6982142da7a22004902e25d5e57 to your computer and use it in GitHub Desktop.

Select an option

Save pupi1985/e463b6982142da7a22004902e25d5e57 to your computer and use it in GitHub Desktop.
refactoring.js
(() => {
var refactoring = () => {
var node = document.createTextNode("Refactored!");
var body = document.getElementsByTagName("BODY")[0];
if (body.hasChildNodes()) {
body.insertBefore(node, body.firstChild);
} else {
body.appendChild(node);
}
};
// If document was already ready then execute immediately
if (document.readyState === "complete") {
refactoring();
} else { // If document is not ready then hook the event
document.addEventListener("readystatechange", function (event) {
if (document.readyState === "complete") {
refactoring();
}
});
}
}).call();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment