PI Search Helper Script

Helper script that selects the first option so you don't have to! Adds some keyboard shortcuts and hides instructions.

2015-05-01 या दिनांकाला. सर्वात नवीन आवृत्ती पाहा.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         PI Search Helper Script
// @namespace    https://greasyfork.org/en/users/10782
// @version      0.2
// @description  Helper script that selects the first option so you don't have to! Adds some keyboard shortcuts and hides instructions.
// @author       tismyname
// @require      https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js  
// @include      https://s3.amazonaws.com/*
// ==/UserScript==

// Makes Instructions Hidable
$(".panel-heading").before('<label><input type="checkbox" id="toggler">Show/Hide Instructions</input><br></label>')
$(".panel-heading").hide();
$(".panel-body").hide();

// Button to show or hide instructions
$('#toggler').click(function() {
    $(".panel-heading").toggle();
    $(".panel-body").toggle();
});    

var ITEMS = 6;
var currentQ = 1;


// Auto Select First Option
for(var i = 1; i <= ITEMS; i++) {
     $('#Q'+i+'_5').click();    
}

// Auto focuses on first radio button
 $('#Q'+currentQ+'_5').focus();

// Sets current clicked element to match keyboard shortcuts
$("input[type=radio]").click(function(){
    currentQ = this.id.charAt(1);
});


// Checks for keypresses
 $(document).keyup(function (event) {
	        var key = toCharacter(event.keyCode);
	        
             
     
	        if (key=='1') {
	            $('#Q'+currentQ+'_5').prop("checked", true);
                
	        }
	        
	        if (key=='2') {
                $('#Q'+currentQ+'_4').prop("checked", true);
	        }
	        
	        if (key=='3') {
	           $('#Q'+currentQ+'_3').prop("checked", true);
	        }
            
            if (key=='4') {
	           $('#Q'+currentQ+'_2').prop("checked", true);
	        }
     
            if (key=='5') {
	           $('#Q'+currentQ+'_1').prop("checked", true);
	        } 
     
            if(key=='N') {
               if(currentQ >= ITEMS)
                   currentQ = 1;
                else {
                   currentQ++;
                }
                $('#Q'+currentQ+'_5').focus();
            }
     
            if(key=='B') {
               if(currentQ <= 1)
                   currentQ = 6;
                else {
                   currentQ--;
                }
                $('#Q'+currentQ+'_5').focus();
            }   
});

// code from https://greasyfork.org/en/scripts/5978-mturk-dave-cobb-hit-helper
function toCharacter(keyCode) {
    // delta to convert num-pad key codes to QWERTY codes.
    var numPadToKeyPadDelta = 48;

	// if a numeric key on the num pad was pressed.
	if (keyCode >= 96 && keyCode <= 105) {
        keyCode = keyCode - numPadToKeyPadDelta;
	    return String.fromCharCode(keyCode);
	}
    
    if (keyCode == 13)
        return "ENTER"; // not sure if I need to add code to hit the submit button
	
    return String.fromCharCode(keyCode);
}