Usa callbacks, que para eso están.
Código Javascript
:
Ver originalif(typeof document.createStyleSheet === 'undefined') {
document.createStyleSheet = function(param){
var index = document.styleSheets.length;
var head=document.getElementsByTagName('head')[0];
if(typeof param == 'string')
{
var element = document.createElement('link');
element.type = 'text/css';
element.rel = 'stylesheet';
element.href = param;
}
else
{
var element = document.createElement('style');
element.type = 'text/css';
}
head.appendChild(element);
function loaded(){
if (typeof param != 'function') return;
if (document.styleSheets.length==index)
{
setTimeout(loaded,1);
}
else
{
param(document.styleSheets[index]);
}
}
loaded();
console.log( element );
}
}
window.onload = function() {
document.createStyleSheet( 'test.css' );
document.createStyleSheet(
function(sheet){
sheet.insertRule('h1 { color: red; }', 0 );
}
);
}