Skip to content

Instantly share code, notes, and snippets.

@BenjaminWolfe
Created August 23, 2022 14:23
Show Gist options
  • Save BenjaminWolfe/d2d18a456d30eda43c4dffd10a737d16 to your computer and use it in GitHub Desktop.
Save BenjaminWolfe/d2d18a456d30eda43c4dffd10a737d16 to your computer and use it in GitHub Desktop.
Typeform Helpers
// background
function timer(ms) { return new Promise(res => setTimeout(res, ms)); }
async function keepGoing(direction, i) {
await timer(500);
const directions = {"up": "previous", "down": "next"};
document.querySelectorAll(`[data-qa="fixed-footer-navigation-${directions[direction]}"]`)[0].click()
await timer(500);
let focusQ = document.querySelectorAll('[data-qa-focused="true"]')[0]
let qId = focusQ.getAttribute('data-qa-blockref');
let qStart = focusQ.querySelector('[data-qa="question-header"]').outerText.substring(0, 64);
console.log(`${i + 1}: ${direction} to ${qId}: ${qStart}`);
}
async function moveTo(qId, direction) {
for (let i = 0; i < 500; i++) {
if (!document.querySelector(`#block-${qId}`)) {
await keepGoing(direction, i);
continue;
}
if (document.querySelector(`#block-${qId}`).getAttribute('data-qa-focused') == 'false') {
await keepGoing(direction, i);
continue;
}
console.log(`${i + 1}: found ${qId}!`)
break;
}
}
// helper functions
function getId() {
return document.querySelectorAll('[data-qa-focused="true"]')[0].getAttribute('data-qa-blockref');
}
async function rewindTo(qId) { moveTo(qId, 'up'); }
async function skipTo(qId) { moveTo(qId, 'down'); }
async function getData() {
const fileHandle = await window.showSaveFilePicker();
const fileStream = await fileHandle.createWritable();
await fileStream.write(new Blob([localStorage.getItem('tf_')], {type: 'text/plain'}));
await fileStream.close();
}
function restoreData(data) { localStorage.setItem('tf_', JSON.stringify(data)); }
@BenjaminWolfe
Copy link
Author

And here's a series of videos walking through those steps visually!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment