// ==UserScript==
// @name mmmturkeybacon Seven Days Dashboard and Weekly Total
// @author mmmturkeybacon
// @description Puts the last seven days, whether they were worked on or not, on the dashboard. Puts the sum of the columns for the week in weekly total fields. Let's you choose which day is the start of the week for calculating the weekly total.
// @namespace http://userscripts.org/users/523367
// @match https://www.mturk.com/mturk/dashboard
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @version 1.11
// @grant GM_getValue
// @grant GM_setValue
// @downloadURL none
// ==/UserScript==
/* WEEK_STARTS_ON let's you choose which day to start the weekly total for:
* Sunday = 0, Monday = 1, Tuesday = 2, Wednesday = 3, Thursday = 4, Friday = 5, Saturday = 6 */
//var WEEK_STARTS_ON = 0;
var WEEK_STARTS_ON = GM_getValue('mmmturkeybacon_seven_days_dashboard_week_start', 0);
$(document).ready(function()
{
var $src;
function append_extra_days()
{
var $last_status_line_link = $('a[href^="/mturk/statusdetail"]').eq(4);
var last_status_line_date = $last_status_line_link.attr('href').substring(32);
var six_days_ago = new Date();
six_days_ago.setMinutes(six_days_ago.getMinutes() - (480 - six_days_ago.getTimezoneOffset())); // set to mturk timezone
six_days_ago.setDate(six_days_ago.getDate() - 6);
//http://stackoverflow.com/questions/3605214/javascript-add-leading-zeroes-to-date
var six_days_ago_date = ('0' + (six_days_ago.getMonth()+1)).slice(-2) + ('0' + six_days_ago.getDate()).slice(-2) + six_days_ago.getFullYear();
var $extra_days = $src.find('a[href^="/mturk/statusdetail"]').filter(function(){return ($(this).attr('href').substring(32) >= six_days_ago_date && $(this).attr('href').substring(32) < last_status_line_date);});
for (var i = $extra_days.length-1; i >= 0; i--)
{
$extra_days.eq(i).parent().attr('class', 'metrics-table-first-value');
$last_status_line_link.parent().parent().after($extra_days.eq(i).parent().parent()[0].outerHTML);
}
}
function insert_missing_days()
{
var date = new Date();
date.setMinutes(date.getMinutes() - (480 - date.getTimezoneOffset())); // set to mturk timezone
var date_today = date.getDate();
var months_short = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var $insertion_ref = $('th[id="user_activities.date_column_header.tooltip"][class="metrics-table-first-header"]').parent();
for (var i = 0; i < 7; i++)
{
var date_zero_formatted = ('0' + (date.getMonth()+1)).slice(-2) + ('0' + date.getDate()).slice(-2) + date.getFullYear();
var date_short_formatted = months_short[date.getMonth()] + ' ' + date.getDate() + ', ' + date.getFullYear();
if (i == 0)
{
date_short_formatted = 'Today';
}
var $status_line_link = $('a[href$="'+date_zero_formatted+'"]');
if ($status_line_link.length <= 0)
{
$insertion_ref.after('