// RedBubble works average views.
// Version 0.1
// 2008-06-06
// Copyright (c) 2008, Dave Pearson <http://www.davep.org/>
// Released under the GPL
// http://www.gnu.org/copyleft/gpl.html
//
// --------------------------------------------------------------------
//
// This is a Greasemonkey user script.  To install it, you need
// Greasemonkey: http://www.greasespot.net/
// Then restart Firefox and revisit this script.
// Under Tools, there will be a new menu item to "Install User Script".
// Accept the default configuration and install.
//
// To uninstall, go to Tools/Manage User Scripts,
// select "RedBubble Works Average Views", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name          RedBubble Works Average Views
// @namespace     http://www.davep.org/
// @description   Add average views to the stats when viewing works.
// @include       http://www.redbubble.com/mybubble/art*
// @include       http://www.redbubble.com/mybubble/clothing*
// @include       http://www.redbubble.com/mybubble/writing*
// @include       http://www.redbubble.com/mybubble/journal*
// ==/UserScript==

// Find the stats.
var stats = document.getElementById( 'stats' );

// If we got the stats...
if ( stats )
{
   // Get the numbers.
   var total = /(\d+) public/.exec( stats.innerHTML );
   var views = /(\d+) views/.exec( stats.innerHTML );

   // If we got them.
   if ( ( total && views ) && ( total[ 1 ] > 0 ) && ( views[ 1 ] > 0 ) )
   {
      // ..stuff the average into the stats too.
      stats.innerHTML += ", " + Math.round( views[ 1 ] / total[ 1 ] ) + " average";
   }
}
