[Script] Dirk Black Enter Key

Discussion in 'mTurk Scripts & Resources' started by ceedj, Feb 3, 2017.

  1. ceedj

    ceedj Survey Slinger

    Messages:
    2,846
    Gender:
    Male
    Ratings:
    +6,319
    Really simple, feel free to break it down and use it however you like. Includes a sanity check, so it should ONLY work on this particular HIT. Thanks to @ChrisTurk for helping me debug something dumb. :)

    Use at your own risk, be sure there is data to be entered, don't blame me for a rejection, blah blah blah.
    EDIT: Added focus to Answer text field.
    Code:
    // ==UserScript==
    // @name         Use Enter to Submit (Dirk Black)
    // @namespace    none
    // @version      1.1
    // @description  Dirk's use Enter Key
    // @author       ceedj
    // @include      https://s3.amazonaws.com/*
    // @include      https://www.mturkcontent.com/*
    // @grant        GM_log
    // @require      http://code.jquery.com/jquery-2.1.0.min.js
    // ==/UserScript==
    
    var Sanity = $('strong:contains(ANNUAL NON-GAAP EARNINGS PER DILUTED SHARE)');
    if (Sanity.length){
    $(document).ready(function() {
    window.focus();
    $("input[id='answer']").focus();
    });
    
    document.onkeydown = function(e) {       
            //Submit
    if (e.keyCode === 13) { // Enter or NumpadEnter
    $("input[id='submitButton']").click();
    }
    } ; 
    }
    
     
    • Like Like x 3
    Last edited: Feb 8, 2017
  2. RicanGuy86

    RicanGuy86 Survey Slinger

    Messages:
    4,452
    Ratings:
    +9,138
    Thanks for this!
     
    • Like Like x 1
  3. slothbear

    slothbear Survey Slinger

    Messages:
    10,822
    Gender:
    Male
    Ratings:
    +22,072
    I added in part of my script...it pastes the highest year into the notes section....sometimes it's useful. Watch out for HITs where the data you want is from a previous year...
    (There's probably a less messy way of doing it...but dirk don't mind....)
    Code:
    // ==UserScript==
    // @name         Use Enter to Submit (Dirk Black)
    // @namespace    none
    // @version      1.0
    // @description  Dirk's use Enter Key, 'Y' to paste highest year
    // @author       ceedj
    // @include      https://s3.amazonaws.com/*
    // @include      https://www.mturkcontent.com/*
    // @grant        GM_log
    // @require      http://code.jquery.com/jquery-2.1.0.min.js
    // ==/UserScript==
    
    var Sanity = $('strong:contains(ANNUAL NON-GAAP EARNINGS PER DILUTED SHARE)');
    if (Sanity.length){
        $(document).ready(function() {
            window.focus();
        });
    
        document.onkeydown = function(e) {      
            //Submit
            if (e.keyCode === 13) { // Enter or NumpadEnter
                $("input[id='submitButton']").click();
            }
            if (e.keyCode === 89) { // Y to put highest year from text into notes
                e.preventDefault();
                getYear();
            }
        };
    }
    
    function getYear(){
        var text = $('td').eq(9).text(); // get relevant text
        var textArray = text.match(/(\d+)/g); // get numbers out of text
        var topYear = 0; // this will eventually be the highest year
        for(var i = 0; i < textArray.length; i++){ // loop through numbers, keep if between 1999 and 2018 and highest year
            if (textArray[i] > 1999 && textArray[i] < 2018 && textArray[i] > topYear) topYear = textArray[i];
        }
       
        if (topYear > 0){ //if topYear is still 0, you don't want it inserted...
            $('#notes').val(topYear);
        }
    }
    
     
    • Like Like x 1
  4. ceedj

    ceedj Survey Slinger

    Messages:
    2,846
    Gender:
    Male
    Ratings:
    +6,319
    Added focus to Answer text field.