Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save proflong/6789929 to your computer and use it in GitHub Desktop.
Save proflong/6789929 to your computer and use it in GitHub Desktop.
<h1>TITLE - change this</h1>
<p>INSTRUCTIONS - change this</p>
<div id="idcheck"><p>To see if you have completed this survey already, enter worker ID below and click 'Check ID'</p><p><textarea rows="1" cols="20" id="idinput"></textarea></p><div id="ok" onclick="check(false)" style="border: 3px solid black;cursor: hand; cursor: pointer; background-color:gray;color:white;width:70px;height:20px;text-align:center;margin-left:10px;">Check ID</div></div>
<p><textarea cols="80" name="comment" rows="3"></textarea></p>
<script type="text/javascript">
var url="URL GOES HERE";//The URL that the user will go to after they are checked (i.e. the survey url). Change this.
var workers=new Array("test1","test1","test3");//This is your white list. Change this. All IDs must be enclosed in quoation marks (single or double), and separated by a comma
//Below is a utility function that checks if a given value is in an array. This will be used to check if the id (given value) is in the white list (an array)
Array.prototype.contains = function(k) {
for(var p in this)
if(this[p] === k)
return true;
return false;
}
//HTML instructions and form for ID input
var naCheck="<p>To see if you have completed this survey already, enter worker ID below and click \'Check ID\'</p><p><textarea rows='1' cols='20' id='idinput'></textarea></p><div id='ok' onclick='check(false)' style='border: 3px solid black;cursor: hand; cursor: pointer; background-color:gray;color:white;width:70px;height:20px;text-align:center;margin-left:10px;'>Check ID</div>";
var href=window.location.href.toString();//Get URL of mturk webpage which may or may not include the worker ID
var queryString={};//storage variable for query string variables
href.replace(new RegExp("([^?=&]+)(=([^&]*))?", "g"),function($0, $1, $2, $3){queryString[$1] = $3;});//Populates variable named queryString (created above) with the actual queryString variable names and values
//If queryString contains a variable names workerId, check if the white list contains that value of that variable, if not, ask the user to input their ID.
if(queryString['workerId']!=undefined)
{
check(queryString['workerId']);//Check ID against white list
}
else
{
document.getElementById('idcheck').innerHTML=naCheck;//Add HTML necessary to ask for id input
}
//This function will check the ID given against the white list, or if not given will check the ID input into the text box against the white list
function check(id){
if(id==false){
if(workers.contains(document.getElementById('idinput').value))
{
//Input ID found on list – send to survey
document.getElementById("idcheck").innerHTML="Your ID is on the list of qualified workers. Please accept the HIT to continue.";
}
else
{
//Input ID not found on list – ask not to accept
document.getElementById("idcheck").innerHTML="Your ID is not on the list of qualified worker. Please do not accept the HIT.";
}
}
else
{
if(workers.contains(id))
{
//Actual ID found on list – send to survey
document.getElementById("idcheck").innerHTML="<p>To proceed to the survey <a href='"+url+'&workerId='+id+"' target='mturksurvey'>click here</a>";
}
else
{
//Actual ID not found on list – ask to return HIT
document.getElementById("idcheck").innerHTML="Your ID is not on the list of qualified worker. Please return the HIT. If you previously entered your ID and were told to accept the HIT, you likely did not enter the correct worker ID.";
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment