Greasy Fork is available in English.

JR Mturk Noblis Image Finder Helper

Makes it easier to select answer for images of people.

Version vom 26.01.2017. Aktuellste Version

// ==UserScript==
// @name        JR Mturk Noblis Image Finder Helper
// @namespace   https://greasyfork.org/users/6406
// @description Makes it easier to select answer for images of people.
// @version     0.16
// @require     http://code.jquery.com/jquery-1.10.2.min.js
// @include     http*://s3.amazonaws.com/TurkAnnotator*
// @grant       none
// ==/UserScript==

var OPEN_URL_AUTO = true;
var CLOSE_POPWINDOW_AFTER = true;

var gQuestions = [];
var gQuestionIndex = 0;
var gOpenedWindow = null;
var gSubmitGo = false;

function checkIdDirections(instructionID,instructionText) {
    var theValue = $("#" + instructionID + ":contains('" + instructionText + "')").length;
    if ($("#" + instructionID).css('display') == "block") return theValue;
    else return false;
}
function isNoblisImages() { return checkIdDirections("instructions_subject_present","Determine whether the person represented by this google image link"); }
function isNoblisAgeImages() { return checkIdDirections("instructions_age","For this task, estimate the age of the person boxed, as best you can."); }
function isNoblisEyeIMages() { return checkIdDirections("instructions_eyes_visible","focus on the eye region of the boxed face in each image"); }
function isNoblisMouthIMages() { return checkIdDirections("instructions_nose_mouth_visible","focus on the nose and mouth region of the boxed face in each image"); }
function isNoblisForeheadIMages() { return checkIdDirections("instructions_forehead_visible","focus on the forehead region of the boxed face in each image as shown below"); }
function isNoblisFacialHairIMages() { return checkIdDirections("instructions_facial_hair","Select the facial hair type that is closest to the person shown below"); }
function isNoblisIndoorOutdoorIMages() { return checkIdDirections("instructions_indoor_outdoor","For this task, choose \"Indoor\" when:"); }
function isNoblisRightEye() { return checkIdDirections("instructions_right_eye_landmark","Click on the center of the person\'s right eye as shown below."); }
function isNoblisLeftEye() { return checkIdDirections("instructions_left_eye_landmark","Click on the center of the person\'s left eye as shown below."); }
function isNoblisNoseBase() { return checkIdDirections("instructions_nose_base_landmark","Click on the center of the base of the person\'s nose as shown below."); }
function isNoblisFindSubject() { return checkIdDirections("instructions_subject_present","face is in the image below by studying the images at"); }

$(function() {
    setTimeout( function() {
        if ( isNoblisImages() ) {
            console.log("Found Noblis Images");
            if (OPEN_URL_AUTO) {
                var personLink = $("#person_link").attr("href");
                var windowWidth = "width=" + screen.width/2;
                var windowHeight = "height=" + (screen.height-(screen.height/10));
                var windowPosition = "left=0," + windowHeight + "," + windowWidth + ",top=0";
                if (personLink) {
                    gOpenedWindow = window.open(personLink,"imagesearch",windowPosition)
                    if (gOpenedWindow) gOpenedWindow.blur();
                    window.focus();
                }
            }
            if ($("#img_boundary")) {
                $("#img_boundary > div").each( function(i,theObject) {
                    if (i>0) {
                        $(theObject).find("div:first").width("140px");
                        $(theObject).find("img:first").css( {marginLeft : "130px"} );
                        $(theObject).find(":radio:eq(0)")[0].nextSibling.nodeValue = "Present (1)";
                        $(theObject).find(":radio:eq(1)")[0].nextSibling.nodeValue = "Not Present (2)";
                        $(theObject).find(":radio:eq(1)").click();
                        $(theObject).find(":radio:eq(2)")[0].nextSibling.nodeValue = "Can't tell (3)";
                        $(theObject).find(":radio:eq(3)")[0].nextSibling.nodeValue = "no Image (0)";
                        gQuestions.push(theObject);
                    }
                });
                $(gQuestions[gQuestionIndex]).css( "background-color", "#66CCCC" );
                $(document).keydown(function(event) {
                    //console.log(gQuestions.length);
                    if (gQuestionIndex<gQuestions.length) {
                        var goToNext = false;
                        if (event.which == 49 || event.which == 97) { // 1 - Present
                            $(gQuestions[gQuestionIndex]).find(":radio:eq(0)").click();
                            goToNext=true;
                        }
                        if (event.which == 50 || event.which == 98) { // 2 - Not Present
                            $(gQuestions[gQuestionIndex]).find(":radio:eq(1)").click();
                            goToNext=true;
                        }
                        if (event.which == 51 || event.which == 99) { // 3 - Can't Tell
                            $(gQuestions[gQuestionIndex]).find(":radio:eq(2)").click();
                            goToNext=true;
                        }
                        if (event.which == 48 || event.which == 96) { // 0 - Image Not Loaded
                            $(gQuestions[gQuestionIndex]).find(":radio:eq(3)").click();
                            goToNext=true;
                        }
                        if (goToNext) {
                            $(gQuestions[gQuestionIndex]).css( "background-color", "" );
                            gQuestionIndex++;
                            if (gQuestionIndex>=gQuestions.length) $("#button_div").css( "background-color", "#66CCCC" );
                            else {
                                $('html, body').animate({
                                    scrollTop: $(gQuestions[gQuestionIndex]).offset().top-21
                                }, 700);
                                $(gQuestions[gQuestionIndex]).css( "background-color", "#66CCCC" );
                            }
                        }
                    } else if (	event.which == 13) {
                        $("#submitbutton").click();
                        event.preventDefault();
                        event.stopPropagation();
                        if (OPEN_URL_AUTO && CLOSE_POPWINDOW_AFTER && gOpenedWindow) gOpenedWindow.close();
                   }
                });
            }
        } else if ( isNoblisRightEye() || isNoblisLeftEye() || isNoblisNoseBase() ) {
            console.log("left or right eye or Nose Base"); // nextbutton notvisiblebutton
            $("#nextbutton").html($("#nextbutton").html() + " (1)");
            $("#notvisiblebutton").html($("#notvisiblebutton").html() + " (2)");
            $(document).keydown(function(event) {
                if (event.which == 49 || event.which == 97) { // 1 - Next
                    if ($("#submitbutton").css('display') == "none") {
                        $("#nextbutton").click();
                        $("#nextbutton").css("background-color","#66FFFF");
                        $("#notvisiblebutton").css("background-color","#E8E8E8");
                    } else if ($("#submitbutton").css('display') == "inline") $("#submitbutton").click();
                }
                if (event.which == 50 || event.which == 98) { // 2 - Not Visible
                    $("#notvisiblebutton").click();
                    $("#notvisiblebutton").css("background-color","#66FFFF");
                    $("#nextbutton").css("background-color","#E8E8E8");
                }
            });
        } else if ( isNoblisEyeIMages() || isNoblisMouthIMages() || isNoblisForeheadIMages() || isNoblisFacialHairIMages() || isNoblisIndoorOutdoorIMages() || isNoblisAgeImages()  || isNoblisFindSubject() ) {
			var facialHairHit = isNoblisFacialHairIMages();
			var indoorOutdoorHit = isNoblisIndoorOutdoorIMages();
			var ageHit = isNoblisAgeImages();
			var findSubject = isNoblisFindSubject();
			$("#nextbutton").focus();
			$("#annotator_div").append($("<div>").css({"margin-top":"300px"}));
			$("#annotator_div input:radio").each( function(index,value) {
				$("#annotator_div").find(":radio:eq(" + index + ")")[0].nextSibling.nodeValue = "(" + (index+1) + ") " + $("#annotator_div").find(":radio:eq(" + index + ")")[0].nextSibling.nodeValue;
			});
			var theCanvas =  ($("#thecanvas").length) ? $("#thecanvas") : $("#img_boundary");
			$('html, body').animate({
				scrollTop: $(theCanvas).offset().top-25
			}, 700);
			$("#image").on("load", function() { $("#button_div").css({"opacity":1.0}); });
            $(document).keydown(function(event) {
				var goToNext = false;
                if (event.which == 49 || event.which == 97) { // 1 - Covered Or Beard or indoor or (0-19)
                    if (indoorOutdoorHit) $("input[value='indoor']:first").click();
                    else if (facialHairHit) $("input[value='beard']:first").click();
                    else if (ageHit) $("input[value='0-19']:first").click();
                    else if (findSubject) $("input[value='Present']:first").click();
                    else $("input[value='covered or partially covered']:first").click();
					goToNext=true;
                }
                if (event.which == 50 || event.which == 98) { // 2 - Not Covered or Moustache or outdoor or (20-34)
                    if (indoorOutdoorHit) $("input[value='outdoor']:first").click();
                    else if (facialHairHit) $("input[value='moustache']:first").click();
                    else if (ageHit) $("input[value='20-34']:first").click();
                    else if (findSubject) $("input[value='Not present']:first").click();
                    else $("input[value='not covered']:first").click();
					goToNext=true;
                }
                if (event.which == 51 || event.which == 99) { // 3 - bad box or Goatee or (35-49)
                    if (facialHairHit) $("input[value='goatee']:first").click();
                    else if (ageHit) $("input[value='35-49']:first").click();
                    else if (findSubject) $("input[value='Can't tell']:first").click();
                    else $("input[value='bad box']:first").click();
					goToNext=true;
                }
                if (event.which == 52 || event.which == 100 && (facialHairHit || ageHit || findSubject)) { // 4 - none or (50-64)
                    if (ageHit) $("input[value='50-64']:first").click();
                    else if (findSubject) $("input[value='Search results unclear']:first").click();
                    else $("input[value='none']:first").click();
					goToNext=true;
                }
                if (event.which == 53 || event.which == 101 && (facialHairHit || ageHit || findSubject)) { // 5 - not visible or (65+)
                    if (ageHit) $("input[value='65+']:first").click();
                    else if (findSubject) $("input[value='Image not loaded']:first").click();
                    else $("input[value='not visible']:first").click();
					goToNext=true;
                }
                if (event.which == 54 || event.which == 102 && (facialHairHit || ageHit)) { // 6 - bad box
                    $("input[value='bad box']:first").click();
					goToNext=true;
                }
				if (goToNext) {
					if ($("#submitbutton").css("display") == "none") setTimeout( function() {
							$("#button_div").css({"opacity":0.3});
							$("#nextbutton").click(); $("#nextbutton").focus(); 
							var theCanvas =  ($("#thecanvas").length) ? $("#thecanvas") : $("#img_boundary");
							$('html, body').animate({
								scrollTop: $(theCanvas).offset().top-25
							}, 700);
						}, 400);
					else { $("#submitbutton").focus(); gSubmitGo = true; }
				}
                if (event.which == 13 && !gSubmitGo) { // enter
					return false;
				}
            });
		}
    }, 1303);
});