Created
February 26, 2011 19:30
-
-
Save longouyang/845528 to your computer and use it in GitHub Desktop.
Small helper file for doing external HITs on Mechanical Turk
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
----------------------------------------------------------------- | |
----------------------------------------------------------------- | |
NOTE: this file has been superseded by mmturkey: | |
https://github.com/longouyang/mmturkey | |
----------------------------------------------------------------- | |
----------------------------------------------------------------- | |
*/ | |
var turk = {}; | |
(function() { | |
var param = function(url, name ) { | |
name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]"); | |
var regexS = "[\\?&]"+name+"=([^&#]*)"; | |
var regex = new RegExp( regexS ); | |
var results = regex.exec( url ); | |
return ( results == null ) ? "" : results[1]; | |
} | |
var src = param(window.location.href, "assignmentId") ? window.location.href : document.referrer; | |
var keys = ["assignmentId","hitId","workerId","turkSubmitTo"]; | |
keys.map( | |
function(key) { | |
turk[key] = unescape(param(src, key)); | |
} | |
); | |
turk.previewMode = (turk.assignmentId == "ASSIGNMENT_ID_NOT_AVAILABLE"); | |
turk.submit = function(data) { | |
var assignmentId = turk.assignmentId; | |
var turkSubmitTo = turk.turkSubmitTo; | |
if (!assignmentId || !turkSubmitTo) return; | |
var dataString = []; | |
for(var key in data) { | |
if (data.hasOwnProperty(key)) { | |
dataString.push(key+"="+escape(data[key])); | |
} | |
} | |
dataString.push("assignmentId="+assignmentId); | |
var url = turkSubmitTo + "/mturk/externalSubmit?" + dataString.join("&"); | |
window.location.href = url; | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Note: this file has been superseded by mmturkey