// ==UserScript==
// @name mmmturkeybacon Last HITs Previewed
// @author mmmturkeybacon
// @description Shows a log of the last 25 HITs that were previewed. This can aid you in contacting a requester, looking at turkopticon ratings, or sharing a HIT. MTurk Great HIT Export and mmmturkeybacon Color Coded Search with Checkpoints should execute after this script so they operate correctly on the page it generates. To see the last 25 HITs previewed visit https://www.mturk.com/mturk/viewhits?last_hits_previewed
// @namespace http://userscripts.org/users/523367
// @match https://www.mturk.com/mturk/preview?*
// @match https://www.mturk.com/mturk/viewhits?last_hits_previewed*
// @require http://code.jquery.com/jquery-latest.min.js
// @version 1.03
// @grant none
// @downloadURL none
// ==/UserScript==
var url = (''+document.location);
var url_ident0 = url.split('?')[0].slice(-7);
var url_ident1 = url.split('?')[1].substr(0,19);
if (url_ident0 == 'preview')
{
var groupId = $('form[name="hitForm"][method="POST"][action="/mturk/hitReview"] > input[name="groupId"]').val();
if (groupId)
{
var hitId = $('form[name="hitForm"][method="POST"][action="/mturk/hitReview"] > input[name="hitId"]').val();
var requesterId = $('input[type="hidden"][name="requesterId"]').val();
var title = $('td[class="capsulelink_bold"][nowrap=""][valign="middle"][width="100%"][align="left"] > div').text().trim();
var requester = $('td[class="capsule_field_title"]').has('a[id="requester.tooltip"]').next('td[class="capsule_field_text"]').text().trim().split(/\u00a0/)[0]; // split at to remove requesterId added by mmmturkeybacon Enhanced HIT Information Capsule
var reward = $('td[class="capsule_field_title"]').has('a[id="reward.tooltip"]').next('td[class="capsule_field_text"]').text().trim().split(' per')[0]; // remove 'per HIT' from reward
var number_of_hits = $('td[class="capsule_field_title"]').has('a[id="number_of_hits.tooltip"]').next('td[class="capsule_field_text"]').text().trim();
var time_left = $('td[class="capsule_field_title"]').has('a[id="time_left.tooltip"]').next('td[class="capsule_field_text"]').text().trim();
var qualifications = $('td[class="capsule_field_title"]').has('a[id="qualifications.tooltip"]').next('td[class="capsule_field_text"]').text().trim();
var date_viewed = (new Date()).toLocaleString();
var hitAutoAppDelayInSeconds = $('input[type="hidden"][name="hitAutoAppDelayInSeconds"]').val();
// time formatting code modified from http://userscripts.org/scripts/show/169154
var days = Math.floor((hitAutoAppDelayInSeconds/(60*60*24)));
var hours = Math.floor((hitAutoAppDelayInSeconds/(60*60)) % 24);
var mins = Math.floor((hitAutoAppDelayInSeconds/60) % 60);
var secs = hitAutoAppDelayInSeconds % 60;
var aa_time = (days == 0 ? '' : days + (days > 1 ? ' days ' : ' day ')) +
(hours == 0 ? '' : hours + (hours > 1 ? ' hours ' : ' hour ')) +
(mins == 0 ? '' : mins + (mins > 1 ? ' minutes ' : ' minute ')) +
(secs == 0 ? '' : secs + (secs > 1 ? ' seconds ' : ' second '));
if (hitAutoAppDelayInSeconds == 0)
{
aa_time = "0 seconds";
}
var previewed_HITs_data_array = JSON.parse(localStorage.getItem('previewed_HITs_data_array'));
if (previewed_HITs_data_array == null)
{
previewed_HITs_data_array = new Array(25);
}
for (var i = 0; i < previewed_HITs_data_array.length; i++)
{
if (previewed_HITs_data_array[i] && previewed_HITs_data_array[i].groupId == groupId)
{
return; // exit
}
}
previewed_HITs_data_array = previewed_HITs_data_array.slice(1);
previewed_HITs_data_array.push({hitId:hitId, groupId:groupId, requesterId:requesterId, title:title, requester:requester, reward:reward, number_of_hits:number_of_hits, time_left:time_left, qualifications:qualifications, date_viewed:date_viewed, aa_time:aa_time});
localStorage.setItem('previewed_HITs_data_array', JSON.stringify(previewed_HITs_data_array));
}
}
else if (url_ident1 == 'last_hits_previewed')
{
document.title = 'Last HITs Previewed';
document.body.innerHTML = '
Last HITs Previewed
';
var previewed_HITs_data_array = JSON.parse(localStorage.getItem('previewed_HITs_data_array'));
var innerHTML = ' \
\
';
for (var i = previewed_HITs_data_array.length-1; i > -1; i--)
{
j = (previewed_HITs_data_array.length-1)-i;
var phda = previewed_HITs_data_array[i];
if (phda == null)
{
continue;
}
innerHTML += ' \
\
\
\
\
\
\
 | \
| \
 | \
\
\
\
\
\
| \
\
\
\
| \
\
| \
\
\
\
\
\
\
\
\
\
Description:\
\
| \
No description available. Automatically approves after '+phda.aa_time+' | \
\
\
\
\
| \
\
| \
| \
\
\
\
 | \
| \
 | \
\
\
\
| \
\
\
\
\
\
| \
\
\
';
}
document.body.innerHTML += innerHTML + '
';
}