updated survey

This commit is contained in:
2026-02-19 22:30:33 +01:00
parent 55f927b564
commit 39ddf07973
6 changed files with 128 additions and 935 deletions

298
index.js
View File

@@ -1,28 +1,20 @@
import { initJsPsych } from 'jspsych';
import 'jspsych/css/jspsych.css';
import jsPsychHtmlKeyboardResponse from '@jspsych/plugin-html-keyboard-response';
import generateUniqueUsernames from './scripts/name-gen.js';
import jsPsychFullscreen from '@jspsych/plugin-fullscreen';
import jsPsychHtmlButtonResponse from '@jspsych/plugin-html-button-response';
import jsPsychLobby from './scripts/plugin-lobby.js';
import jsPsychSurvey from '@jspsych/plugin-survey';
import '@jspsych/plugin-survey/css/survey.css';
import './styles.css';
import { getStimulusMap } from './scripts/text-stimuli.js';
import jsPsychObjectMoving from './scripts/plugin-object-moving.js';
import { textStimuli } from './scripts/text-stimuli.js';
const total_participants = import.meta.env.VITE_TOTAL_PARTICIPANTS || 2;
const uniqueUsernames = generateUniqueUsernames(total_participants);
const experiment_name = import.meta.env.VITE_EXPERIMENT_NAME;
let prolific_id;
let probe_condition; // will be set to neutral or reveal based on the condition
let probe_condition; // will be set to ai or human based on the condition.
let debug = false;
const short_version = true; // just using the short version of the task
let probe_order; // will be set to ai_first or human_first based on the condition
function delayed_redirect(url) {
setTimeout(() => {
@@ -31,13 +23,13 @@ function delayed_redirect(url) {
}
const jsPsych = initJsPsych({
on_finish: function () {
on_finish: function() {
jsPsych.getDisplayElement().innerHTML = textStimuli.complete;
},
on_close: function () {
on_close: function() {
delayed_redirect(import.meta.env.VITE_CLOSED_URL);
},
on_data_update: function () {
on_data_update: function() {
if (debug) {
console.log(jsPsych.data.get().json());
}
@@ -50,43 +42,62 @@ prolific_id = jsPsych.data.getURLVariable('PROLIFIC_PID');
const COND = Number(jsPsych.data.getURLVariable('C'));
const probe_preamble = 'In this experiment, you worked together with a partner. ';
const probe_closing_text = 'Please share any suspicions you had about your partner during the experiment by indicating your agreement with the following statements.';
const probe_preamble = `In this experiment, we told you that you would roll a die to determine the difficulty of the captcha task.\nHowever, `;
const probe_closing_text = `\n\nPlease share your thoughts and suspicions about this by indicating your agreement with the following statements.`;
const probe_text_neutral = probe_preamble + probe_closing_text;
const probe_text_reveal = probe_preamble + 'However, due to the difficulty of implementing multi-participant online studies, your partner was actually an AI agent trained to behave like a human participant. ' + probe_closing_text;
let together_colour;
const probe_text_die =
probe_preamble +
'the die roll was rigged, so that the number you received (and therefore the difficulty of the captcha task) was pre-determined. ' +
probe_closing_text;
const probe_text_difficulty =
probe_preamble +
'while the die roll was random, the difficulty of the captcha task was pre-determined and unrelated to the die roll. ' +
probe_closing_text;
switch (COND) {
case 0:
probe_condition = 'neutral';
together_colour = 'blue';
probe_condition = 'die';
probe_order = 'die_first';
break;
case 1:
probe_condition = 'neutral';
together_colour = 'red';
probe_condition = 'die';
probe_order = 'die_first';
break;
case 2:
probe_condition = 'reveal';
together_colour = 'blue';
probe_condition = 'difficulty';
probe_order = 'die_first';
break;
case 3:
probe_condition = 'reveal';
together_colour = 'red';
probe_condition = 'difficulty';
probe_order = 'die_first';
break;
case 4:
probe_condition = 'die';
probe_order = 'difficulty_first';
break;
case 5:
probe_condition = 'die';
probe_order = 'difficulty_first';
break;
case 6:
probe_condition = 'difficulty';
probe_order = 'difficulty_first';
break;
case 7:
probe_condition = 'difficulty';
probe_order = 'difficulty_first';
break;
}
const stimulusMap = getStimulusMap(together_colour);
const stimulusMap = getStimulusMap();
const props = {
condition: probe_condition,
together_colour: together_colour,
prolific_id: prolific_id,
experiment_name: experiment_name,
probe_order: probe_order,
cond: COND,
}
};
if (debug) {
console.log(props);
@@ -111,85 +122,19 @@ const consent_form = {
type: jsPsychHtmlButtonResponse,
stimulus: stimulusMap.get('consent'),
choices: ['Exit', 'Continue'],
on_finish: function (data) {
on_finish: function(data) {
if (data.response === 0) {
jsPsych.abortExperiment(stimulusMap.get('no_consent'));
}
},
};
const initial_lobby = {
type: jsPsychLobby,
user_names: uniqueUsernames,
end_number: total_participants,
start_text: 'Searching for a partner',
end_text: 'Partner found, the experiment will begin shortly.',
join_interval: 5000,
show_avatars: false,
};
const lobby_slow = {
type: jsPsychLobby,
user_names: uniqueUsernames,
end_number: total_participants,
start_text: 'Waiting for your partner',
end_text: 'Your partner is ready, the experiment will continue shortly.',
show_avatars: false,
join_interval: 7000,
};
const lobby_fast = {
type: jsPsychLobby,
user_names: uniqueUsernames,
end_number: total_participants,
start_text: 'Waiting for your partner',
end_text: 'Your partner is ready, the experiment will continue shortly.',
show_avatars: false,
join_interval: 500,
};
const multi_user_instructions = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('multi_user_instructions'),
};
const instructions_1 = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('instructions_1'),
};
const instructions_2 = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('instructions_2'),
};
const instructions_3 = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('instructions_3'),
};
const instructions_4 = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('instructions_4'),
};
const pre_practice_instructions = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('pre_practice_instructions'),
};
const pre_task_instructions = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
stimulus: stimulusMap.get('pre_task_instructions'),
};
const debrief = {
type: jsPsychHtmlKeyboardResponse,
choices: [' '],
@@ -202,14 +147,27 @@ const pre_survey_info = {
stimulus: stimulusMap.get('pre_survey_info'),
};
const survey_function = (survey) => {
survey.onAfterRenderPage.add(function (sender, options) {
const die_probe_row = {
text:
'I suspected that the die roll was not random, or the number I received was pre-determined.',
value: 'SuspicionDie',
};
const difficulty_probe_row = {
text:
'I suspected that, contrary to what I was told, the captcha task difficulty was not determined by the die roll.',
value: 'SuspicionDifficulty',
};
const survey_function = survey => {
survey.onAfterRenderPage.add(function(sender, options) {
console.log('Survey page rendered:', sender.currentPage);
if (survey.activePage.name === 'page1') {
if (survey.activePage.name === 'page2') {
const nextButton = document.querySelector('#sv-nav-next > div > input');
if (nextButton) {
let seconds = 15;
const originalText = nextButton.value.replace(/\s*\(\d+\)$/, '') || 'Continue';
let seconds = 20;
const originalText =
nextButton.value.replace(/\s*\(\d+\)$/, '') || 'Continue';
nextButton.disabled = true;
nextButton.value = `${originalText} (${seconds})`;
const interval = setInterval(() => {
@@ -224,8 +182,7 @@ const survey_function = (survey) => {
}
}
});
}
};
const survey = {
type: jsPsychSurvey,
@@ -242,21 +199,27 @@ const survey = {
elements: [
{
type: 'matrix',
name: probe_condition === 'neutral' ? probe_text_neutral : probe_text_reveal,
name:
'Please answer the following questions about your experience in the captcha task.',
alternateRows: true,
isAllRowRequired: debug ? false : true,
rowOrder: 'random',
rows: [
{
text: 'I believed that my partner was actually an AI agent or a bot.',
value: 'SuspicionPartner',
text: `I found the captcha task difficult.`,
value: 'Difficulty',
},
{
text: `There's no question here. Select 'Disagree' to show that you're paying attention.`,
value: 'AttentionCheck',
text: `I think I solved all the captchas correctly.`,
value: 'Accuracy',
},
{
text: 'I believed that my partner was another, human, participant.',
value: 'ConfidencePartner',
text: `I think I solved captchas faster than most other participants would have.`,
value: 'Relative_performance',
},
{
text: `I think I solved captchas slower than most other participants would have.`,
value: 'Relative_performance_slow',
},
],
columns: [
@@ -286,6 +249,55 @@ const survey = {
},
{
name: 'page2',
elements: [
{
type: 'matrix',
name:
probe_condition === 'die'
? probe_text_die
: probe_text_difficulty,
alternateRows: true,
isAllRowRequired: debug ? false : true,
rowOrder: 'random',
rows: [
probe_order === 'die_first'
? die_probe_row
: difficulty_probe_row,
{
text: `There's no question here. Select 'Disagree' to show that you're paying attention.`,
value: 'AttentionCheck',
},
probe_order === 'die_first'
? difficulty_probe_row
: die_probe_row,
],
columns: [
{
value: 5,
text: 'Strongly agree',
},
{
value: 4,
text: 'Agree',
},
{
value: 3,
text: 'Neutral',
},
{
value: 2,
text: 'Disagree',
},
{
value: 1,
text: 'Strongly disagree',
},
],
},
],
},
{
name: 'page3',
elements: [
{
type: 'radiogroup',
@@ -314,60 +326,13 @@ const survey = {
defaultValue: 18,
},
],
}
},
],
},
};
const factors = {
selector: ['partner', 'participant'],
together_side: ['left', 'right'],
location: short_version ? [33, 50, 66] : [32, 33, 34, 49, 50, 51, 65, 66, 67],
};
const practice_factors = {
selector: ['partner', 'participant'],
together_side: ['left', 'right'],
location: [50],
};
const trials = jsPsych.randomization.factorial(factors, 1);
if (debug) {
console.log(factors);
console.log(trials);
}
const practice_trials = jsPsych.randomization.factorial(practice_factors, 1);
const object_moving_trials = {
timeline: [
{
type: jsPsychObjectMoving,
selector: jsPsych.timelineVariable('selector'),
together_side: jsPsych.timelineVariable('together_side'),
location: jsPsych.timelineVariable('location'),
together_colour: together_colour,
},
],
timeline_variables: trials,
};
const object_moving_practice = {
timeline: [
{
type: jsPsychObjectMoving,
selector: jsPsych.timelineVariable('selector'),
together_side: jsPsych.timelineVariable('together_side'),
location: jsPsych.timelineVariable('location'),
together_colour: together_colour,
},
],
timeline_variables: practice_trials,
};
if (debug) {
timeline.push(survey)
timeline.push(survey);
timeline.push(debrief);
}
@@ -375,18 +340,7 @@ if (!debug) {
timeline.push(pre_consent_info);
timeline.push(consent_form);
timeline.push(enter_fullscreen);
timeline.push(multi_user_instructions);
timeline.push(initial_lobby);
timeline.push(instructions_1);
timeline.push(instructions_2);
timeline.push(instructions_3);
timeline.push(instructions_4);
timeline.push(pre_practice_instructions);
timeline.push(lobby_slow);
timeline.push(object_moving_practice);
timeline.push(pre_task_instructions);
timeline.push(lobby_fast);
timeline.push(object_moving_trials);
timeline.push(pre_survey_info);
timeline.push(survey);
timeline.push(debrief);