// RedBubble Stats Scraper for My RedBubble
// Version 0.1
// 2008-09-18
// Copyright (c) 2008, Matt Simner
// 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 Stats Scraper", and click Uninstall.
//
// --------------------------------------------------------------------
//
// ==UserScript==
// @name RedBubble Stats Scraper
// @namespace http://www.mattsimner.com/
// @description Retrieve stats from My RedBubble on each item (works for clothing, art, journals etc)
// @include http://www.redbubble.com/mybubble/art*
// @include http://www.redbubble.com/mybubble/clothing*
// @include http://www.redbubble.com/mybubble/journal*
// @include http://www.redbubble.com/mybubble/writing*
// @include http://www.redbubble.com/mybubble/calendars*
// @exclude http://www.redbubble.com/mybubble/*/*
// ==/UserScript==
// Add jQuery
var GM_JQ = document.createElement('script');
GM_JQ.src = 'http://www.mattsimner.com/google/redbubble/jquery-1.2.6.min.js';
GM_JQ.type = 'text/javascript';
document.getElementsByTagName('head')[0].appendChild(GM_JQ);
// Check if jQuery's loaded
function GM_wait()
{
if(typeof unsafeWindow.jQuery == 'undefined') { window.setTimeout(GM_wait,100); }
else { $ = unsafeWindow.jQuery; letsJQuery(); }
}
GM_wait();
// All your GM code must be inside this function
function letsJQuery()
{
//OK - we know we're on an applicable My Redbubble page - so we're only interested in the stats. We're going to
//get all of these from the page (including the summary) and build a collection that we can spit out into different formats.
//We'll initially support CSV for Excel use, but may go to XML etc (as we're just talking formatting).
var statsType = $(".mybubble > h1").text();
var stats = new Array();
var i = 0;
var works = $(".works_list tr").each(function() //for each item in works list
{
var currentWork = $(this);
stats[i] = new WorkInformation();
//stats[i].ID = 0;
stats[i].Description = $(".description .title > a", currentWork).text();
var currentWorkStats = $(".stats li", currentWork).each(function() //for each stat in this work
{
var statText = $(this).text();
GM_log(statText);
var spaceIndex = statText.indexOf(" ");
var statType = statText.substr(spaceIndex +1, statText.length - spaceIndex);
var statValue = statText.substr(0, spaceIndex);
GM_log(statType);
GM_log(statValue);
statValue
//We have the 'type' so put the value in the right bucket
switch(statType)
{
case "sales":
case "sale":
stats[i].Sales = statValue;
break;
case "comments":
case "comment":
stats[i].Comments = statValue;
break;
case "favoritings":
stats[i].Favouritings = statValue;
break;
case "views":
stats[i].Views = statValue;
break;
default:
stats[i].Views = 0;
stats[i].Favouritings = 0;
stats[i].Comments = 0;
stats[i].Sales = 0;
break;
}
var dt = new Date();
stats[i].AsOf = FormatSortableDate(dt);
});
i++;
});
//Now spit out into a usable format (CSV)
var csvOutput = "AsOf;Description;Sales;Comments;Favouritings;Views\n";
for(var item = 0; item < stats.length; item++)
{
csvOutput += stats[item].AsOf + ";" + stats[item].Description + ";" + stats[item].Sales + ";" + stats[item].Comments + ";" + stats[item].Favouritings + ";" + stats[item].Views + "\n";
}
//GM_log(csvOutput);
$("
").insertAfter(".works_list");
$("#csvStats").text(csvOutput);
$("#csvStats").attr("style", "border: 1px solid #333333; font-family: monotype, courier new; font-size: 1.2em; background-color: #ececec; margin-top: 10px; padding: 6px");
}
function FormatSortableDate(dateToFormat)
{
return dateToFormat.getFullYear() + "-" + (dateToFormat.getMonth() +1 ) + "-" + dateToFormat.getDate() + " " + dateToFormat.getHours() + ":" + dateToFormat.getMinutes() + ":" + dateToFormat.getSeconds()
}
function WorkInformation(id, asOf, description, sales, comments, favouritings, views)
{
//this.ID = id;
this.AsOf = asOf
this.Description = description;
this.Sales = sales;
this.Comments = comments;
this.Favouritings = favouritings;
this.views = views;
}