MTurk EyeApps

Add keyboard shortcuts to EyeApps HITs

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name        MTurk EyeApps
// @namespace   http://idlewords.net
// @description Add keyboard shortcuts to EyeApps HITs
// @include     https://www.mturkcontent.com/dynamic/hit*
// @version     0.1
// @require     https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js
// @grant       none
// ==/UserScript==

function keyHandler(event, index) {
	var rating_id = "-1";
	switch(event.which) {
		case 48:
		case 96:
			rating_id = "10";
			break;
		case 49:
		case 97:
			rating_id = "1";
			break;
		case 50:
		case 98:
			rating_id = "2";
			break;
		case 51:
		case 99:
			rating_id = "3";
			break;
		case 52:
		case 100:
			rating_id = "4";
			break;
		case 53:
		case 101:
			rating_id = "5";
			break;
		case 54:
		case 102:
			rating_id = "6";
			break;
		case 55:
		case 103:
			rating_id = "7";
			break;
		case 56:
		case 104:
			rating_id = "8";
			break;
		case 57:
		case 105:
			rating_id = "9";
	}

	var doScrollDown = false;
	var isRated = false;

	if (rating_id != "-1") {
		$("input[id=rating" + index + "_" + rating_id +"]").prop('checked', true);
		doScrollDown = true;
		isRated = true;
	}

	if ($("input[name='rating" + index + "']:checked").val() !== undefined) {
		isRated = true;
	}

	var idWord = '';
	if (event.which == 73) { //"I"nappropriate
		idWord = "Inappropriate";
	} else if (event.which == 71) { //I don't "g"et it
		idWord = "Idontgetit";
	} else if (event.which == 68 || event.which == 67) { //
		idWord = "baddisplay";
	}

	if (idWord) {
		if ($("#" + idWord + index).prop('checked') === true) {
			$("#" + idWord + index).prop('checked', false);
		} else {
			$("#" + idWord + index).prop('checked', true);
		}
		if (isRated || event.which == 68 || event.which == 67) {
			doScrollDown = true;
		}
	}

	var scrollTarget = '';
	var focusTarget = '';
	if (index+1 == $("[id^=ratingbox]").length) {
		scrollTarget = "#submitButton";
		focusTarget = "#submitButton";
	} else {
		scrollTarget = "#headline_" + (index+1);
		focusTarget = "#ratingbox_" + (index+1);
	}

	if ((event.which == 9 && !event.shiftKey) || doScrollDown) {
		event.preventDefault();
		$(scrollTarget).get(0).scrollIntoView();
		$(focusTarget).focus();
	} else if (event.which == 9 && event.shiftKey && index != 0) {
		event.preventDefault();
		$("#headline_" + (index-1)).get(0).scrollIntoView();
		$("#ratingbox_" + (index-1)).focus();
	}

}

if ($("p:contains('For the text and images below')").length) {
	$("h2").each(function(index, element) {
		$(this).attr('id', 'headline_' + index);
		$(this).addClass('headline');
		$(this).html('<input type="text" name="ratingbox" value="" id="ratingbox_' + index + '" readonly="readonly" />&nbsp;&nbsp;' + $(this).text());
		$("#ratingbox_" + index).css('width', '5px').css('border-color', 'blue');
		$("#ratingbox_" + index).keydown(function(event) {
			keyHandler(event, index);
		});
	});

	$('[id^="ratingbox"]').each(function(r_index, element) {
		$(this).focus(function(f_index, element) {
			$(this).css('border-color', 'red');
		});
		$(this).blur(function(b_index, element) {
			$(this).css('border-color', 'blue');
		});
	});
	
	var i = 0;
	$("input[type='radio'][name^='rating']").each(function(radio_index, element) {
		i++;
		if (i == 11) {
			i = 1;
		}
		$(this).attr('id', $(this).attr('name') + '_' + i);
	});

	$("#headline_0").get(0).scrollIntoView();
	$("#ratingbox_0").focus();
}