Wakefield's Daily Tips

Skipping dialogue boxes online

At the start of every PsychoJS experiment you get a dialogue box asking for your participant number, etc. This shouldn’t be hidden and I would recommend that you don’t change the default key “participant” since it gets used in the data file name.

On the other hand you might want your participant to launch the study straight away, especially if you have already assigned a value for participant, etc. using daisy chaining or a custom participation link.

If you want to skip the dialogue box put this code into the Before Experiment tab of a JavaScript code component.

var checkOK = setInterval(function() { //Use basic nested setInterval for Status check of dialog
    console.log("Check if DialogBox loaded");
   if (document.getElementById("progressMsg")) { //Wait for ProgressMsg to exist
        console.log("Dialogbox exists."); //Dialog Box Ready
      var statusText = document.getElementById("progressMsg").innerHTML; //get Status of ProgressMsg
      if(statusText == "all resources downloaded.") //If status is good. Go and let JS Click the button
      {
      console.log("All resources were downloaded! Press Ok now...");
      document.getElementById("dialogOK").click(); // Click on the checkbox
      clearInterval(checkOK);
      }
   }
}, 500); // check every 500ms

What is does it try to press the OK button every 500 milliseconds, so that experiment starts as soon as it is ready. However, your experiment will then launch in a normal browser tab, rather than full screen. The first routine will have to be in a tab, but as soon as you have had user interaction (probably a mouse click or key press) then you can add the following JavaScript code (for example in End Routine)

psychoJS.window.fullscr = true;
psychoJS.window.adjustScreenSize();

You can also use similar code in End Experiment to auto-press the “Thank you for your patience” message after the data has saved, though in this case there isn’t an issue about not being in full screen.

var checkOK = setInterval(function() {

  // Wait for the element containing "Thank you for your patience" to exist
  var thankYouElement = document.querySelector(".scrollable-container");
    if (thankYouElement) {
      console.log("Thank you element found.", thankYouElement.innerText);

      // If the text includes "Thank you for your patience," click the OK button
      if (thankYouElement.innerText.includes("Thank you for your patience")) {
        // Get the status of the OK button
        var statusOK = document.getElementById("dialogOK").innerHTML;
        console.log("Press Ok now...", statusOK);

        // Click on the OK button if it's enabled
        var okButton = document.getElementById("dialogOK");
        if (okButton && !okButton.disabled) {
          console.log("Clicking OK button...");
          okButton.click();
        } else {
          console.log("OK button is not enabled.");
        }

        // Stop the interval
        clearInterval(checkOK);
      }
    }
  }, 100); // Check every 100ms

Of course, if you change the message in this box in Experiment Settings / Online, you will need to change the code accodingly.