// ==UserScript==
// @name           styl-lich
// @namespace      http://eldar.cz/myf/firefox/
// @description    loads external stylesheet on (all | given pages) and/or disables their initial ones
// @include        *
// ==/UserScript==

// include : (if present) regExp required to match the URL for apply.
// cssUrl : (if present) url of desired css.
// killer : true will disable all other stylesheets

var Rules =
[{ cssUrl: 'http://eldar.cz/myf/pub/firefox/myfavolours.user.css'
 , include: /^http:\/\/(www.)?eldar/
 , killer: true
 }
,{ cssUrl: 'http://eldar.cz/myf/pub/firefox/accesskeys.user.css'
 }
,{ cssUrl: 'http://foo.bar/noop.css'
 , include: /^ do not match $/
 , killer: true
 }

]

var head = document.getElementsByTagName("head")[0];

for ( var i = 0; i < Rules.length; i++ ) {
 if ( !Rules[i].include || document.location.href.match(Rules[i].include) ) {
  if (Rules[i].killer) {
   for ( var j = 0; j < document.styleSheets.length; j++ ) {
    document.styleSheets[j].disabled = true;
   }
  }
  if (Rules[i].cssUrl) {
   var cssNode = document.createElement('link');
   cssNode.type = 'text/css';
   cssNode.rel = 'stylesheet';
   cssNode.href = Rules[i].cssUrl;
   cssNode.media = Rules[i].media ? Rules[i].media : 'screen';
   cssNode.title = Rules[i].title ? Rules[i].title : 'dynamicLoadedSheet';
   head.appendChild(cssNode);
  }
 }
}


// thx
// http://www.hunlock.com/blogs/Howto_Dynamically_Insert_Javascript_And_CSS

