// DeviantART - CSS Nullify v0.3 RC1
// Made By Luke Stevenson {http://lucanos.deviantart.com/}
// Distributed and Maintained via GMVC
// Last updated: 18 December 2006
//
//   This script provides the option to disable Custom CSS in deviantArt
// Journals
//
// ==UserScript==
// @name              DeviantART - CSS Nullify
// @namespace         http://gmvc.lucanos.com/
// @description       (v0.3 RC1) Provides a "Toggle CSS" button to allow for the Custom Journal CSS to be switched on and off.
// @include           http://*.deviantart.com*
// ==/UserScript==

var arrSheets;

(function () {

  if ( document.styleSheets.length>5 ) {

    // Some form of Custom CSS Present

    var CSSCont = document.createElement('div');
      CSSCont.style.right = '3px';
      CSSCont.style.position = 'absolute';
      CSSCont.style.padding = '0 2px 2px 2px';
      CSSCont.style.color = '#000000';
      CSSCont.style.backgroundColor = '#bac5ba';
      CSSCont.style.zIndex = '50';

    var CSSLink = document.createElement('a');
      CSSLink.textContent = '[ Toggle CSS ]';
      CSSLink.style.color = '#000000';

	arrSheets = new Array();
	  
	if ( document.styleSheets[2].cssRules[0].selectorText!=".not-ready" ) {
      // Stylesheet #2 is Not Standard
	  arrSheets[arrSheets.length] = 2;
	}

    if ( document.styleSheets.length>6 ) {
	  // There are additional Stylesheets within the Page
	  for ( var i=6; i<document.styleSheets.length; i++ ) {
	    arrSheets[arrSheets.length] = i;
	  }
    }
	
	CSSLink.href = "javascript:var arrSheets=new Array('"+arrSheets.join("','")+"');for (var a=0; a<arrSheets.length; a++ ){void(document.styleSheets[arrSheets[a]].disabled=(document.styleSheets[arrSheets[a]].disabled?false:true))};";

    // Find The Journals
    var journals = document.evaluate("//div[contains(@class,'journalbox')]", document, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);

    // For Each Journal, Add the Toggle Button
    for (var i = journals.snapshotLength - 1; i >= 0; i--) {
    
      CSSCont.appendChild( CSSLink );

      journals.snapshotItem(i).parentNode.insertBefore( CSSCont , journals.snapshotItem(i) );
    }
  } else {
    // No Custom CSS
  }

})();
