<commit_before>// load essential variables
var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split("&"),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split("=");

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};
var hit_id = getUrlParameter("hit_id");
var worker_id = getUrlParameter("worker_id");
var assignment_id = getUrlParameter("assignment_id");
var mode = getUrlParameter("mode");
var participant_id = getUrlParameter("participant_id");

// stop people leaving the page
window.onbeforeunload = function() {
    return "Warning: the study is not yet finished. " +
    "Closing the window, refreshing the page or navigating elsewhere " +
    "might prevent you from finishing the experiment.";
};

// allow actions to leave the page
var allow_exit = function() {
    window.onbeforeunload = function() {};
};

// advance the participant to a given html page
var go_to_page = function(page) {
    window.location = "/" + page + "?participant_id=" + participant_id;
};

// report assignment complete
var submitAssignment = function() {
    reqwest({
        url: "/participant/" + participant_id,
        method: "get",
        type: "json",
        success: function (resp) {
            mode = resp.participant.mode;
            hit_id = resp.participant.hit_id;
            assignment_id = resp.participant.assignment_id;
            worker_id = resp.participant.worker_id;
            var worker_complete = '/worker_complete';
            reqwest({
                url: worker_complete,
                method: "get",
                type: "json",
                data: {
                    "uniqueId": worker_id + ":" + assignment_id
                },
                success: function (resp) {
                    allow_exit();
                    window.location = "/complete";
                },
                error: function (err) {
                    console.log(err);
                    var errorResponse = JSON.parse(err.response);
                    $("body").html(errorResponse.html);
                }
            });
        }
    });
};

var submit_assignment = function () {
    submitAssignment();
};

// make a new participant
var create_participant = function() {
    var url;
    // check if the local store is available, and if so, use it.
    if (typeof store != "undefined") {
        url = "/participant/" +
            store.get("worker_id") + "/" +
            store.get("hit_id") + "/" +
            store.get("assignment_id") + "/" +
            store.get("mode");
    } else {
        url = "/participant/" +
            worker_id + "/" +
            hit_id + "/" +
            assignment_id + "/" +
            mode;
    }

    var deferred = $.Deferred();
    if (participant_id !== undefined && participant_id !== 'undefined') {
        deferred.resolve();
    } else {
        $(function () {
            $('.btn-success').prop('disabled', 'disabled');
            reqwest({
                url: url,
                method: "post",
                type: "json",
                success: function(resp) {
                    console.log(resp);
                    participant_id = resp.participant.id;
                    if (resp.quorum) {
                        if (resp.quorum.n === resp.quorum.q) {
                            // reached quorum; resolve immediately
                            deferred.resolve();
                        } else {
                            // wait for quorum, then resolve<commit_msg>Fix enabling button after creating participant<commit_after>// load essential variables
var getUrlParameter = function getUrlParameter(sParam) {
    var sPageURL = decodeURIComponent(window.location.search.substring(1)),
        sURLVariables = sPageURL.split("&"),
        sParameterName,
        i;

    for (i = 0; i < sURLVariables.length; i++) {
        sParameterName = sURLVariables[i].split("=");

        if (sParameterName[0] === sParam) {
            return sParameterName[1] === undefined ? true : sParameterName[1];
        }
    }
};
var hit_id = getUrlParameter("hit_id");
var worker_id = getUrlParameter("worker_id");
var assignment_id = getUrlParameter("assignment_id");
var mode = getUrlParameter("mode");
var participant_id = getUrlParameter("participant_id");

// stop people leaving the page
window.onbeforeunload = function() {
    return "Warning: the study is not yet finished. " +
    "Closing the window, refreshing the page or navigating elsewhere " +
    "might prevent you from finishing the experiment.";
};

// allow actions to leave the page
var allow_exit = function() {
    window.onbeforeunload = function() {};
};

// advance the participant to a given html page
var go_to_page = function(page) {
    window.location = "/" + page + "?participant_id=" + participant_id;
};

// report assignment complete
var submitAssignment = function() {
    reqwest({
        url: "/participant/" + participant_id,
        method: "get",
        type: "json",
        success: function (resp) {
            mode = resp.participant.mode;
            hit_id = resp.participant.hit_id;
            assignment_id = resp.participant.assignment_id;
            worker_id = resp.participant.worker_id;
            var worker_complete = '/worker_complete';
            reqwest({
                url: worker_complete,
                method: "get",
                type: "json",
                data: {
                    "uniqueId": worker_id + ":" + assignment_id
                },
                success: function (resp) {
                    allow_exit();
                    window.location = "/complete";
                },
                error: function (err) {
                    console.log(err);
                    var errorResponse = JSON.parse(err.response);
                    $("body").html(errorResponse.html);
                }
            });
        }
    });
};

var submit_assignment = function () {
    submitAssignment();
};

// make a new participant
var create_participant = function() {
    var url;
    // check if the local store is available, and if so, use it.
    if (typeof store != "undefined") {
        url = "/participant/" +
            store.get("worker_id") + "/" +
            store.get("hit_id") + "/" +
            store.get("assignment_id") + "/" +
            store.get("mode");
    } else {
        url = "/participant/" +
            worker_id + "/" +
            hit_id + "/" +
            assignment_id + "/" +
            mode;
    }

    var deferred = $.Deferred();
    if (participant_id !== undefined && participant_id !== 'undefined') {
        deferred.resolve();
    } else {
        $(function () {
            $('.btn-success').prop('disabled', true);
            reqwest({
                url: url,
                method: "post",
                type: "json",
                success: function(resp) {
                    console.log(resp);
                    $('.btn-success').prop('disabled', false);
                    participant_id = resp.participant.id;
                    if (resp.quorum) {
                        if (resp.quorum.n === resp.quorum.q) {
                            // reached quorum; resolve immediately
                            deferred.resolve();
                        } else {
                            // wait for quorum, then resolve
{'fraction_non_alphanumeric': 0.12509855453350854, 'fraction_numerical': 0.001314060446780552, 'mean_word_length': 1.7308934337997848, 'pattern_counts': {'":': 4, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3512225', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1988, 'n_words': 484}