// ==UserScript==
// @icon http://www.woodus.com/den/gallery/graphics/dq9ds/shield/silver_platter.png
// @name Customer Interests - Product Interest / Keyword Relevance Audit [mturk]
// @namespace Scripts->Foundation->Humans
// @version 1.1.8.2017.09.27
// @description Automatically selects a default value on Customer Interest hits, focuses in frame, and allows custom key to radio element bindings.
// @author D.M.K. & R.E.G. @ MegaCorp, Inc
// @include https://s3.amazonaws.com/mturk_bulk/hits/*
// @include https://www.mturkcontent.com/dynamic/*
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js
// @PANDA https://www.mturk.com/mturk/previewandaccept?groupId=3KAZLCS3F9ALRMAYYRWSFLQTNUFAPT (Keyword Relevance to Interest Audit)
// @PANDA https://www.mturk.com/mturk/previewandaccept?groupId=36ARV8EEI75YW67UK35RLDFB7MHAVL (Product to Interest Audit)
// @PANDA https://www.mturk.com/mturk/previewandaccept?groupId=34KQN2TBLUDI4EQQQ80MAQV63FLAS7 (Produkt zum Interesse Relevanz Audit)
// @TEST_LINK https://s3.amazonaws.com/mturk_bulk/hits/275394612/SrFWZUmNqGj7BmxnX0fUGg.html?assignmentId=ASSIGNMENT_ID_NOT_AVAILABLE&hitId=3PIOQ99R7YK4YAD76BQH1FC89QLUNZ
// @compatible Known to work on: Chrome 46+, Tampermonkey v4.3.6+, Windows 7 x64
// ==/UserScript==
/* jshint expr: true */ // Make JSHint shut up about short circuiting
/* USER configurable settings */
const DEFAULT_UR_CLICK = $(':radio')[1]; // No
//const DEFAULT_UR_CLICK = $(':radio')[0]; // Yes
const DEFAULT_IR_CLICK = $(':radio')[0]; // Yes
//const DEFAULT_IR_CLICK = $(':radio')[1]; // No
/* Action keys */
// NOTE: Format of jump table is keycode and number (index) of the desired radio button. These were labeled KEY_YES, KEY_NO, KEY_DEBATE and KEY_SKIP, but this is variable based on number of radio buttons.
// For example, the Product Interest doesn't have 'Debatable'. The submit key is a special case: it's 13 by default, but can be anything; the 'radio' binding is always ignored.
const KEY_SUBMIT = 13; // default submit key; must be set here and below.
const JUMP_TABLE = { 97: 0, // NP1 - radio button 1 (Usually Yes)
49: 0, // 1
98: 1, // NP2 - radio button 2 (Usually No)
50: 1, // 2
99: 2, // NP3 - radio button 3 (Debatable or Skip (rarely used))
100: 3, // NP4 - radio button 4 (Usually Skip)
13: 666 // Submit. keycode:ignored (can't just use KEY_SUBMIT, javascript doesn't recognize const x = 1 as x equaling 1!)
};
/* Utility Constants */
const DEFAULT_FOCUS = $(':radio')[0];
const MAGIC_KEY_GOAL = "The goal is to answer the question:Is the keyword uniquely relevant to the interest?";
const MAGIC_ITEM_GOAL = "The goal is to answer the question: Is the item relevant to the interest?";
const MAGIC_ITEM_SEX = "The goal is to answer the question: Is the item relevant to the interest and not sexually explicit?";
const MAGIC_DOUCHE = "Das Ziel ist, die Frage zu beantworten: Ist der Artikel für das Interesse relevant?";
/* Sanity check function */
const magic = $('.panel-body>p').text();
/* Key handler */
const addKeyJumpHandler = j=>{document.addEventListener('keydown',e=>{if (j.hasOwnProperty(k=e.which)){e.preventDefault();if (k === KEY_SUBMIT) $('#submitButton').click(); else (r= $(':radio')[j[k]]) && r.click();}});};
$(function() {
if (magic === MAGIC_KEY_GOAL || magic === MAGIC_ITEM_SEX || magic === MAGIC_ITEM_GOAL || magic === MAGIC_DOUCHE) {
console.info(`${GM_info.script.name} ${GM_info.script.version}`);
Ç(['.panel-primary']);
addKeyJumpHandler(JUMP_TABLE);
DEFAULT_FOCUS.focus();
if (magic === MAGIC_KEY_GOAL) DEFAULT_UR_CLICK.click();
else if (magic === MAGIC_ITEM_GOAL || magic === MAGIC_DOUCHE) DEFAULT_IR_CLICK.click();
}
});
function Ç(å) {if (å.length){const ï = "Instructions";$('body').prepend('<button id="☢" type="button" style="width: 8em;float: none;border-radius: 42%;outline:none;">-'+ï+'</button>');
$("#☢").click(()=>{$('#☢').text((ì,Œ)=>{return (Œ.slice(0,1) === '+'?'-':'+')+ï;});å.forEach((µ)=>{$(µ).toggle();});}).click()[0].scrollIntoView();}}
// Auxiliary notes:
// AHK for Three Monitors using number pad 5 to submit and go to next window:
// NumPad5::
// Send {Enter}
// Send !{Tab 2}
// return
// AHK to cycle to the next tab:
// NumPad5::
// Send {Enter}
// Send {LCtrl down}{Tab}{LCtrl up}
// return