Untitled

mail@pastecode.io avatar
unknown
javascript
a month ago
2.5 kB
3
Indexable
Never
Qualtrics.SurveyEngine.addOnload(function()
{
	    var headerCont = document.createElement("div");  
 headerCont.className = "header-cont";  
 headerCont.id = "header_container";  
 var header = document.createElement("div");  
 header.className = "header"  
 header.id = "header_1";  
 var timer = document.createElement("div");  
 timer.className = "timer";  
 timer.id = "timer_1";  
 timer.innerHTML = "Time Remaining: <span id='time'>05:00</span>";  
 headerCont.appendChild(header);  
 header.appendChild(timer);  
 document.body.insertBefore(headerCont, document.body.firstChild);
function startTimer(duration, display) {  
  var timer = duration, minutes, seconds;  
  var myTimer = setInterval(function() {  
   minutes = parseInt(timer / 60, 10)  
   seconds = parseInt(timer % 60, 10);  
   minutes = minutes < 10 ? "0" + minutes : minutes;  
   seconds = seconds < 10 ? "0" + seconds : seconds;  
   var text = ('innerText' in display)? 'innerText' : 'textContent';
   display[text] = minutes + ":" + seconds;  
   if (--timer < 0) {  
    clearInterval(myTimer);  
    timeOver();  
   }  
  }, 1000);  
 }  
	
	 // List of relevant question IDs
    var relevantQuestionIds = ["QID65", "QID84", "QID87", "QID88", "QID89", "QID90", "QID155"];

    // Check if any relevant question is present on the current page
    var isRelevantQuestionPresent = relevantQuestionIds.some(function(questionId) {
        return document.getElementById(questionId) !== null;
    });

    if (isRelevantQuestionPresent) {
        startTimer(timerSeconds, display);
    } else {
        // Clear the timer if it was previously set
        clearInterval(myTimer);
        document.getElementById("header_container").style.display = "none";
    }
	
	
 var timerSeconds = 30,  
 display = document.querySelector('#time');  
 startTimer(timerSeconds, display);  
 var timeOver = function() {  
	 
     document.getElementById("timer_1").innerHTML = "Time is over.";
     Qualtrics.SurveyEngine.setEmbeddedData("TimeFlag1", "1");
	 var q = document.getElementById("QID95"); 
        if (q) {
            q.style.display = "none";
        }
	 

     // $('NextButton').click();
	 // TODO: set below to display=none AND move to tıme ıs over page
 }

});

Qualtrics.SurveyEngine.addOnReady(function()
{
	/*Place your JavaScript here to run when the page is fully displayed*/

});

Qualtrics.SurveyEngine.addOnUnload(function()
{
	/*Place your JavaScript here to run when the page is unloaded*/

});
Leave a Comment