// ==UserScript==
// @name spamcop.net - Reporting enhancements
// @author Michael A. Chase 
// @namespace http://home.ix.netcom.com/~mchase/ 
// @version 1.0.0
// @description  Enhances various aspects of the Spamcop spam reporting
//			tool.
// @ujs:category site: enhancements
// @ujs:published 2005-08-24 20:10
// @ujs:modified 2005-09-25 07:48
// @ujs:documentation http://userjs.org/scripts/site/enhancements/spamcop-net-reporting-fixes 
// @ujs:download http://userjs.org/scripts/download/site/enhancements/spamcop-net-reporting-fixes.js 
// @include http://mailsc.spamcop.net/reportheld*
// @include http://mailsc.spamcop.net/sc*
// @include http://mailsc.spamcop.net/
// ==/UserScript==

/* 
 * Copyright © 2005 by Michael A. Chase
 * 
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License.
 * 
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 * USA
 */


if ( 0 == window.location.href.indexOf("http://mailsc.spamcop.net/sc?") ) {
  document.addEventListener( "load", function() {

    var courier_replacement_font = "monospace";

    var elems, l, count, i, elem, font, title_prefix, new_location;
    if ( null != courier_replacement_font && "" != courier_replacement_font ) {
      // Replace font "courier" with an easier to read font.
      elems = document.getElementsByTagName("font");
      l     = elems.length;
      count = 0;
      for ( i = 0; i < l; ++i ) {
        elem = elems[i];
        if ( elem.face && "courier" == elem.face ) {
          elem.face = courier_replacement_font;
          ++count;
        }
      }
      // alert( "Replaced face in " + count + " of " + l + " font tags." );

      // Replace font-family "courier" in divs.
      elems = document.getElementsByTagName("div");
      l     = elems.length;
      count = 0;
      for ( i = 0; i < l; ++i ) {
        elem = elems[i];
        font = window.getComputedStyle( elem, null ).
          getPropertyValue("font-family");
          // Returns the value in quotes.  Argh!
        if ( font.match( /^"?courier"?/i ) ) {
          elem.style.setProperty( "font-family", courier_replacement_font,
            null );
          ++count;
        }
      }
      // alert( "Replaced font-family in " + count + " of " + l + " div tags." );
    }

    // Change links for #report to #footer if there is no anchor named report.
    if ( document.getElementById("report") ) {
      // Set title and move immediately to anchor "report".
      title_prefix = "1";
      new_location = "#report";
    }
    else {
      // Redirect links to "#report" to "#footer" instead.
      var elems, l, count, i, elem;
      elems = document.getElementsByTagName("a");
      l     = elems.length;
      count = 0;
      for ( i = 0; i < l; ++i ) {
        elem = elems[i];
        if ( elem.href && elem.href.match( "#report$" ) ) {
          elem.href = "#footer";
          ++count;
        }
      }
      // Move immediately to anchor "footer".
      title_prefix = "0";
      new_location = "#footer";
      // alert( "Replaced href in " + count + " of " + l + " a tags." );
    }
    if ( new_location ) {
      location.replace( new_location ); // don't add to history
      // location.href = new_location;     // add to history
    }
    if ( null != title_prefix ) {
      elem = document.getElementsByTagName("title")[0].firstChild;
      elem.nodeValue = title_prefix + " " + elem.nodeValue;
    }
  }, false );
}

else if ( "http://mailsc.spamcop.net/" == window.location.href ||
    0 == window.location.href.indexOf("http://mailsc.spamcop.net/sc") ) {
  document.addEventListener( "load", function() {
    // Skip intermediate page if a link to actual report page is available.
    var elems, l, count, i, elem, title_prefix, new_location;
    elems = document.getElementsByTagName("a");
    l     = elems.length;
    if ( 0 == l ) {
      // No links at all, just go unless already there.
      // Example: Text file full of "HTTP/1.1 100 Continue"
      if ( "http://mailsc.spamcop.net/" != window.location.href ) {
        new_location = "/";
      }
      // alert( "a tags found.\n" + new_location );
    }
    else {
      // Some links, find link to next Report Spam page.
      title_prefix = "0";
      count = 0;
      for ( i = 0; i < l; ++i ) {
        elem = elems[i];
        ++count;
        if ( elem.href &&
          0 == elem.href.indexOf("http://mailsc.spamcop.net/sc?") ) {
          title_prefix = null;
          new_location = elem.href;
          break;
        }
      }
      // alert( "Searched for 'sc?' in " + count + " of " + l + " a tags.\n" + new_location );
    }
    if ( new_location ) {
      // location.replace( new_location ); // don't add to history
      location.href = new_location;     // add to history
    }
    if ( !title_prefix ) {
      elem = document.getElementsByTagName("title")[0].firstChild;
      elem.nodeValue = title_prefix + " " + elem.nodeValue;
    }
  }, false );
}

else if ( 0 == window.location.href.indexOf("http://mailsc.spamcop.net/reportheld") &&
  0 != window.location.href.indexOf("http://mailsc.spamcop.net/reportheld?action=preview") ) {
  document.addEventListener( "load", function() {
    var elems, l, count, i, elem, new_location;
    elem = document.log;
    if ( elem ) {
      if ( elem.checked ) {
        // Have checkboxes, set subaction, check all checkboxes, and set title..
        elem.subaction.value = "rqd";
        checkAll('checked');
        l = elem.checked.length;
        if ( !l ) l = 1;
        elem = document.getElementsByTagName("title")[0].firstChild;
        elem.nodeValue = l + " " + elem.nodeValue;
      }
      else {
        // No checkboxes.
        if ( "http://mailsc.spamcop.net/reportheld" == window.location.href ) {
          // No action parameter, refetch to avoid complaints on refresh.
          new_location = "/reportheld?action=heldlog";
        }
        else {
          // Form serves no purpose, deavtivate it.
          window.validSelection = function() { return false; };
        }
      }
    }
    else {
      // No form, refetch with action parameter.
      new_location = "/reportheld?action=heldlog";
    }
    if ( new_location ) {
      location.replace( new_location ); // don't add to history
      ///location.href = new_location;     // add to history
    }
  }, false );
}
// :indentSize=2:

