// ==UserScript==
// @name Show HIT Details on Tasks page
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Add details for HITs on the detail status bar
// @author JRB
// @match https://worker.mturk.com/projects/*/tasks*
// @grant none
// ==/UserScript==
function getElementsByXPath(xpath, parent)
{
let results = [];
let query = document.evaluate(xpath,
parent || document,
null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
for (let i=0, length=query.snapshotLength; i<length; ++i) {
results.push(query.snapshotItem(i));
}
return results;
}
function formatDate(date) {
var monthNames = [
"January", "February", "March",
"April", "May", "June", "July",
"August", "September", "October",
"November", "December"
];
var day = date.getDate();
var monthIndex = date.getMonth();
var year = date.getFullYear();
return day + ' ' + monthNames[monthIndex] + ' ' + year;
}
(function() {
'use strict';
var hitDetailsLink = getElementsByXPath("//a[text()='HIT Details']")[0];
var hitDetailsParent = hitDetailsLink.parentElement;
var hitModalData = JSON.parse(hitDetailsParent.getAttribute("data-react-props"));
var detailBarRow = getElementsByXPath("//div[contains(@class, 'project-detail-bar')]/div[contains(@class, 'row')]")[0];
var numAssignableHITs = hitModalData.modalOptions.assignableHitsCount;
var requesterName = hitModalData.modalOptions.requesterName;
var projectTitle = hitModalData.modalOptions.projectTitle;
var timeAllotted = Math.round(hitModalData.modalOptions.assignmentDurationInSeconds / 60);
var expirationTime = formatDate(new Date(hitModalData.modalOptions.expirationTime));
var contactRequesterLink = hitModalData.modalOptions.contactRequesterUrl;
var myDiv = document.createElement('div');
myDiv.className = "col-md-12 col-xs-12";
myDiv.innerHTML = '<span class="detail-bar-label">Requester Name: </span><span class="detail-bar-value"><a href="' + contactRequesterLink + '" target="_blank">' + requesterName + '</a></span>';
myDiv.innerHTML += ' <span class="detail-bar-label">HITs Available: </span><span class="detail-bar-value">' + numAssignableHITs + '</span>';
myDiv.innerHTML += ' <span class="detail-bar-label">HIT Title: </span><span class="detail-bar-value">' + projectTitle + '</span>';
myDiv.innerHTML += ' <span class="detail-bar-label">Time Allotted: </span><span class="detail-bar-value">' + timeAllotted + ' Min</span>';
myDiv.innerHTML += ' <span class="detail-bar-label">Expires: </span><span class="detail-bar-value">' + expirationTime + '</span>';
detailBarRow.append(myDiv);
})();