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

function cssNullify() {

  var arrStyle = document.getElementsByTagName('style');
  var arrJournal = new Array();

  // Check each of the STYLE's contents for the string 'custom journal css'
  for ( var i=0; i<arrStyle.length; i++ ) {
    if ( arrStyle[i].innerHTML.match( 'custom journal css' ) ) {
      arrJournal[arrJournal.length] = i;
    }
  }
  
  if ( arrJournal.length>0 ) {
    // Custom Journal CSS found

    // Create the Button Container
    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';

    // Create the Button
    var CSSLink = document.createElement('a');
      CSSLink.textContent = '[ Toggle CSS ]';
      CSSLink.style.color = '#000000';

    // Set the Button Link
    CSSLink.href = "javascript:"+
                   "var cssArr=new Array('"+arrJournal.join(',')+"');"+
                   "for(var a=0;a<cssArr.length;a++){"+
                     "void(document.getElementsByTagName('style')[cssArr[a]].disabled=(document.getElementsByTagName('style')[cssArr[a]].disabled?false:true))"+
                   "};";

    // Put the Button inside the Container
    CSSCont.appendChild( CSSLink );

    // 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=0 ; i<journals.snapshotLength ; i++ ) {
      journals.snapshotItem(i).parentNode.insertBefore( CSSCont , journals.snapshotItem(i) );
    }

  } else {
    // No Custom Journal CSS
  }

}
cssNullify();
