Skip to content

Instantly share code, notes, and snippets.

@proflong
Created September 30, 2013 22:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save proflong/6770997 to your computer and use it in GitHub Desktop.
Save proflong/6770997 to your computer and use it in GitHub Desktop.
Using a black list to exclude certain mturk workers from HITs (especially surveys).
<h1>TITLE - change this</h1>
<p>INSTRUCTIONS - change this</p>
<div id="idcheck">&nbsp;</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 black 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 black 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 black 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 black list
}
else
{
document.getElementById('idcheck').innerHTML=naCheck;//Add HTML necessary to ask for id input
}
//This function will check the ID given against the black list, or if not given will check the ID input into the text box against the black list
function check(id){
if(id==false){
if(workers.contains(document.getElementById('idinput').value))
{
//Input ID found on list -- taken the survey before, ask not to accept
document.getElementById("idcheck").innerHTML="Your ID is on the list of workers who have completed this survey already. Please do not accept the HIT. Thank you for your previous participation.";
}
else
{
//Input ID not found on list -- ask to accept, when this happens it will start the program over again, this time checking their actual ID not their inputted ID, which should be the same
document.getElementById("idcheck").innerHTML="Your ID is not on the list of workers who have completed this survey. Please accept the HIT to continue.";
}
}
else
{
if(workers.contains(id))
{
//Actual ID found on list -- ask to return HIT (this should rarely happen, if ever... it basically means the person did not follow instructions or tried to lie before hand
document.getElementById("idcheck").innerHTML="Your ID is on the list of workers who have completed this survey already. 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.";
}
else
{
//Actual ID not 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>";
}
}
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment