Skip to content

Instantly share code, notes, and snippets.

@thevolcanomanishere
Created January 23, 2025 15:32
Show Gist options
  • Save thevolcanomanishere/8a739ab918ab20057652272d4e6d2ace to your computer and use it in GitHub Desktop.
Save thevolcanomanishere/8a739ab918ab20057652272d4e6d2ace to your computer and use it in GitHub Desktop.
Qualtrics Dev Mode bookmarklet
javascript:(()=>{let e,t="",n;function i(e,t,n=!1){let i=document.createElement("div");i.style.marginBottom="10px",i.style.border="1px solid #ddd",i.style.borderRadius="4px";let o=document.createElement("div");o.style.padding="10px",o.style.backgroundColor="#f5f5f5",o.style.cursor="pointer",o.style.userSelect="none",o.innerHTML=`<span style="margin-right: 5px">${n?"▼":"▶"}</span>${e}`;let l=document.createElement("div");return l.style.padding="10px",l.style.display=n?"block":"none",l.appendChild(t),o.onclick=()=>{let e="block"===l.style.display;l.style.display=e?"none":"block",o.firstChild.textContent=e?"▶":"▼"},i.appendChild(o),i.appendChild(l),i}function o(e){let t=document.createElement("div"),n=document.createElement("div");n.innerHTML=`
<div style="margin-bottom: 5px"><strong>Question ID:</strong> ${e.QuestionID}</div>
<div style="margin-bottom: 5px"><strong>Type:</strong> ${e.QuestionType}</div>
<div style="margin-bottom: 5px"><strong>Selector:</strong> ${e.Selector}</div>
`,t.appendChild(i("General Info",n));let o=document.createElement("div");if(o.innerHTML=e.QuestionText,t.appendChild(i("Question Text",o)),e.Choices){let l=document.createElement("div");Object.entries(e.Choices).forEach(([e,t])=>{l.innerHTML+=`
<div style="margin-bottom: 10px; padding: 5px; border-bottom: 1px solid #eee">
<div><strong>Choice ${e}:</strong> ${t.Text}</div>
<div style="color: #666; font-size: 11px">
Variable: ${t.VariableName} |
Recode: ${t.RecodeValue} |
Exclusive: ${t.Exclusive}
</div>
</div>
`}),t.appendChild(i("Choices",l))}if(e.Validation){let r=document.createElement("pre");r.style.margin="0",r.textContent=JSON.stringify(e.Validation,null,2),t.appendChild(i("Validation",r))}let d=document.createElement("pre");return d.style.margin="0",d.textContent=JSON.stringify(e,null,2),t.appendChild(i("Raw Data",d)),t}function l(e){let t=Qualtrics.SurveyEngine.QuestionInfo;Object.entries(t).forEach(([t,n])=>{let l=document.createElement("div");l.innerHTML=`
<strong>${n.QuestionID}</strong> -
<span style="color: #666">Type: ${n.QuestionType}</span>
`;let r=o(n);e.appendChild(i(l.innerHTML,r))})}function r(){e&&e.remove(),Object.assign((e=document.createElement("div")).style,{position:"fixed",top:"20px",right:"20px",padding:"15px",background:"white",border:"1px solid #ccc",borderRadius:"5px",maxHeight:"90vh",overflow:"auto",width:"400px",zIndex:"10000",fontFamily:"system-ui, -apple-system, sans-serif",fontSize:"13px",boxShadow:"0 2px 10px rgba(0,0,0,0.1)"});let t=document.createElement("div");t.innerHTML='<h3 style="margin: 0 0 15px 0">Questions on Page</h3>',e.appendChild(t);let n=document.createElement("button");n.textContent="\xd7",n.onclick=()=>e.remove(),Object.assign(n.style,{position:"absolute",top:"5px",right:"5px",padding:"5px 10px",border:"none",background:"none",cursor:"pointer",fontSize:"20px"}),e.appendChild(n);let i=document.createElement("button");i.textContent="↻",i.onclick=d,Object.assign(i.style,{position:"absolute",top:"5px",right:"30px",padding:"5px 10px",border:"none",background:"none",cursor:"pointer",fontSize:"16px"}),e.appendChild(i),l(e),document.body.appendChild(e)}function d(){if(!Qualtrics?.SurveyEngine?.QuestionInfo)return;let e=JSON.stringify(Object.keys(Qualtrics.SurveyEngine.QuestionInfo));e!==t&&(t=e,r())}function s(){n||(n=setTimeout(()=>{d(),n=null},500))}let p=new MutationObserver(s);p.observe(document.body,{childList:!0,subtree:!0}),d()})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment