-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.js
44 lines (41 loc) · 1.51 KB
/
lib.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// Source: https://s3.amazonaws.com/mturk-public/externalHIT_v1.js
function turkGetParam( name, defaultValue ) {
var regexS = "[\?&]"+name+"=([^&#]*)";
var regex = new RegExp( regexS );
var tmpURL = window.location.href;
var results = regex.exec( tmpURL );
if( results == null ) {
return defaultValue;
} else {
return results[1];
}
}
function UTWorkerLimitReached(ut_id, workerId, assignmentId) {
var assignmentId = assignmentId || turkGetParam('assignmentId', '');
if (assignmentId != '' && assignmentId != 'ASSIGNMENT_ID_NOT_AVAILABLE') {
var workerId = workerId || turkGetParam('workerId', '');
var url = '//uniqueturker.myleott.com/'+ut_id+'/'+workerId+'/'+assignmentId;
var response = turkGetParam('ut_response', '-1');
if (window.XDomainRequest) {
if (response == '-1') {
// Use Microsoft XDR
var xdr = new XDomainRequest();
xdr.open("get", url, true);
xdr.onload = function() {
response = xdr.responseText;
window.location.replace(window.location.href + "&ut_response="+response);
};
xdr.send();
}
} else {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.send();
response = request.responseText;
}
if (response == '0') {
return true;
}
}
return false;
}