// ==UserScript==
// @name mmmturkeybacon Butt-in Buttons
// @version 1.03
// @description Adds a PandA (previewandaccept: accepts a HIT from within in the group at random) link/button. Adds a Pick & Roll button that accepts the very HIT you are previewing (if still available) and then skips to a new HIT. Adds the automatically accept checkbox to HIT previews. Shows the Accept button and CAPTCHAs right away. Adds a RandA button that returns a HIT and loads the HIT's PandA URL. Makes the Return button red.
// @author mmmturkeybacon
// @namespace http://userscripts.org/users/523367
// @match https://www.mturk.com/mturk/preview?*
// @match https://*.mturk.com/mturk/previewandaccept?*
// @match https://*.mturk.com/mturk/accept?*
// @match https://*.mturk.com/mturk/continue?*
// @match https://*.mturk.com/mturk/submit?*
// @match https://*.mturk.com/mturk/return?*
// @run-at document-start
// @require https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js
// @grant GM_addStyle
// @downloadURL none
// ==/UserScript==
// following line borrowed from: https://greasyfork.org/en/scripts/5918-mturk-show-captcha-and-accept-button-asap/code
GM_addStyle("#javascriptDependentFunctionality { display: block !important; }");
$(document).ready(function()
{
//var GENERIC_BUTTON_COLOR = '#ffd15f';
//var GENERIC_BUTTON_COLOR = '#fbc134';
var GENERIC_BUTTON_COLOR = '#a6cdde';
var RANDA_BUTTON_COLOR = '#ff0000';
var $isAccepted = $('input[type="hidden"][name="isAccepted"]');
//if (window.location.href.indexOf('https://www.mturk.com/mturk/preview?') > -1)
if ($isAccepted.val() == 'false') //preview
{
var hitId = $('input[type="hidden"][name="hitId"]').attr('value');
var prevHitSubmitted = $('input[type="hidden"][name="prevHitSubmitted"]').attr('value');
var prevRequester = $('input[type="hidden"][name="prevRequester"]').attr('value');
var requesterId = $('input[type="hidden"][name="requesterId"]').attr('value');
var prevReward = $('input[type="hidden"][name="prevReward"]').attr('value');
var hitAutoAppDelayInSeconds = $('input[type="hidden"][name="hitAutoAppDelayInSeconds"]').attr('value');
var groupId = $('input[type="hidden"][name="groupId"]').attr('value');
var signature = $('input[type="hidden"][name="signature"]').attr('value');
var autoAcceptEnabled = $('input[value="on"][name="autoAcceptEnabled"][type="checkbox"]').is(':checked') ? '&autoAcceptEnabled=on' : '';
var panda_URL = 'https://www.mturk.com/mturk/previewandaccept?groupId='+groupId;
var pick_and_roll_URL = 'https://www.mturk.com/mturk/accept?hitId='+hitId+'&prevHitSubmitted='+prevHitSubmitted+'&prevRequester='+encodeURIComponent(prevRequester).replace(/%20/g,'+')+'&requesterId='+requesterId+'&prevReward='+prevReward+'&hitAutoAppDelayInSeconds='+hitAutoAppDelayInSeconds+'&groupId='+groupId+'&signature='+signature;
var skip_URL = $('img[src="/media/skip_hit.gif"][height="22"][width="68"][border="0"]').parent().attr('href');
//* top buttons*/
var $buttons_table_top = $('td[valign="top"][width="200"][align="center"] > table[cellpadding="0"][cellspacing="0"][border="0"]');
$buttons_table_top.parent().prev()[0].width = '10%';
$buttons_table_top.parent()[0].width = '400';
$buttons_table_top.parent().next()[0].width = '10%';
var $first_row = $buttons_table_top.find('tr:eq(0)');
$first_row.after('
');
$first_row.remove();
var $spacer_td = $buttons_table_top.find('tr:eq(1) > td:eq(1)');
$spacer_td.after('
');
$spacer_td.after('
');
$spacer_td.remove();
//* bottom buttons*/
var $buttons_table_bottom = $('div[align="center"] > table[cellpadding="0"][cellspacing="0"][border="0"]');
var $first_row = $buttons_table_bottom.find('tr:eq(0)');
$first_row.after('
');
$first_row.remove();
var $spacer_td = $buttons_table_bottom.find('tr:eq(1) > td:eq(1)');
$spacer_td.after('
');
$spacer_td.after('
');
$spacer_td.remove();
//* listeners */
$('input[value="on"][name="autoAcceptEnabled"][type="checkbox"]').bind( 'click', function(){autoAcceptEnabled = $(this).is(':checked') ? '&autoAcceptEnabled=on' : ''; $('a[id^="mtbpar_panda_a"]').attr('href', panda_URL+autoAcceptEnabled)} );
// preventDefault prevents the form from being submitted as if the Accept button had been pressed.
$('button[id^="mtbpar_pick_btn"]').bind('click', function(event){ event.preventDefault(); $.get(pick_and_roll_URL, function(data){window.location.href = skip_URL}) });
$('button[id^="mtbpar_panda_btn"]').bind('click', function(event){ event.preventDefault(); window.location.href = panda_URL+autoAcceptEnabled; });
$('td[nowrap=""][align="center"]:contains("Want to work on this HIT?")').each(function()
{
var $parent_table = $(this).parent().parent();
$parent_table.append('
');
$spacer_td.remove();
//* listeners */
$('input[value="on"][name="autoAcceptEnabled"][type="checkbox"]').bind( 'click', function(){autoAcceptEnabled = $(this).is(':checked') ? '&autoAcceptEnabled=on' : ''; $('a[id^="mtbpar_panda_a"]').attr('href', panda_URL+autoAcceptEnabled)} );
// preventDefault prevents the form from being submitted as if the Accept button had been pressed.
$('button[id^="mtbpar_randa_btn"]').bind('click', function(event){ event.preventDefault(); $.get(return_URL, function(data){window.location.href = panda_URL+autoAcceptEnabled}) });
}
}
// else $isAccepted.val() is undefined so it is not a HIT
});