您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
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.
当前为
// ==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 // ==/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('<tr class="even"><td class="metrics-table-first-value"><a href="/mturk/statusdetail?encodedDate='+date_zero_formatted+'">'+date_short_formatted+'</a></td><td>0</td><td>0</td><td>0</td><td>0</td><td><span class="reward">$0.00</span></td></tr>') $insertion_ref = $('a[href$="'+date_zero_formatted+'"]').parent().parent(); } else { $insertion_ref = $status_line_link.parent().parent(); } date.setDate(date.getDate() - 1); } } function clean_up() { var $status_line_links = $('a[href^="/mturk/statusdetail"]'); for (var i = $status_line_links.length-1; i >= 7; i--) { // remove all status lines that didn't fall in the last 7 days $status_line_links.eq(i).parent().parent().remove(); } $('th[id="user_activities.date_column_header.tooltip"][class="metrics-table-first-header"]').parent().nextAll('tr').each(function(index) { $(this).attr('class', ((index % 2 == 0) ? 'even' : 'odd')); }); } function append_weekly_total() { $('tr[id="mtb_total_line"]').remove(); var previous_sunday = new Date(); previous_sunday.setMinutes(previous_sunday.getMinutes() - (480 - previous_sunday.getTimezoneOffset())); // set to mturk timezone previous_sunday.setDate(previous_sunday.getDate() - ((7 - WEEK_STARTS_ON + previous_sunday.getDay()) % 7)); var previous_sunday_date = ('0' + (previous_sunday.getMonth()+1)).slice(-2) + ('0' + previous_sunday.getDate()).slice(-2) + previous_sunday.getFullYear(); var submitted_total = 0; var approved_total = 0; var rejected_total = 0; var pending_total = 0; var earnings_total = 0; var $this_week = $src.find('a[href^="/mturk/statusdetail"]').filter(function(){return ($(this).attr('href').substring(32) >= previous_sunday_date);}); $this_week.each(function() { submitted_total += parseInt($(this).parent().parent().find('td:eq(1)').text(), 10); approved_total += parseInt($(this).parent().parent().find('td:eq(2)').text(), 10); rejected_total += parseInt($(this).parent().parent().find('td:eq(3)').text(), 10); pending_total += parseInt($(this).parent().parent().find('td:eq(4)').text(), 10); earnings_total += parseInt($(this).parent().parent().find('span[class="reward"]').text().replace(/[^0-9]/g,''), 10); }); // //<option value="1">Monday</option><option value="2">Tuesday</option><option value="3">Wednesday</option><option value="4">Thursday</option><option value="5">Friday</option><option value="6">Saturday</option> //$('a[href^="/mturk/statusdetail"]').last().parent().parent().after('<tr class="odd"><td colspan="5">Weekly Total</td><td><span class="reward">'+'$' + (total/100).toFixed(2)+'</span></td></tr>'); $('a[href^="/mturk/statusdetail"]').last().parent().parent().after('<tr id="mtb_total_line" class="grayHead"><td style="font: bold 12px arial, sans-serif; color: #369; width: 60%; text-align: left; padding-left: 15px;">Total For The Week Starting On: <select id="mtb_day_select"><option value="0">Sunday</option><option value="1">Monday</option><option value="2">Tuesday</option><option value="3">Wednesday</option><option value="4">Thursday</option><option value="5">Friday</option><option value="6">Saturday</option></select></td><td style="font: bold 12px arial, sans-serif; color: #369">'+submitted_total+'</td><td style="font: bold 12px arial, sans-serif; color: #369">'+approved_total+'</td><td style="font: bold 12px arial, sans-serif; color: #369">'+rejected_total+'</td><td style="font: bold 12px arial, sans-serif; color: #369">'+pending_total+'</td><td style="font: bold 12px arial, sans-serif; color: #369"><span class="reward">'+'$' + (earnings_total/100).toFixed(2)+'</span></td></tr>'); $('select[id="mtb_day_select"]').prop('selectedIndex', WEEK_STARTS_ON); $('select[id="mtb_day_select"]')[0].onchange = function(){WEEK_STARTS_ON = this.selectedIndex; GM_setValue('mmmturkeybacon_seven_days_dashboard_week_start', this.selectedIndex); append_weekly_total();}; } $.get('/mturk/status', function(data) { $src = $(data); var maxpagerate = $src.find("td[class='error_title']:contains('You have exceeded the maximum allowed page request rate for this website.')"); if (maxpagerate.length == 0) { append_extra_days(); insert_missing_days(); clean_up(); append_weekly_total(); } }); });