Extracting questions from Google Forms
Before the making of a great Google Forms form, I abstract my questions in a piece of paper. Or a text file. And later I will just input them manually by hand on Google Forms.
Next, what if I need to invert the process. I need a text file of my Google Forms and I wont do it manually because it is too much.
I have an interactive form that consist of 21 section that if I take the screenshot of it and print it, it will requires 14 pages of A4 paper.
So I open my browser developer tool and spend 1 hour to write this simple script.
var template = [
[
"[aria-label='Form title']",
(el) => el.getAttribute("aria-label") == "Form title",
(el) => `* ${el.innerText.replace("\n", "")}`,
],
[
"[aria-label='Section title (optional)']",
(el) => el.getAttribute("aria-label") == "Section title (optional)",
(el) => `* ${el.innerText.replace("\n", "")}`,
],
[
"[aria-label='Question']",
(el) => el.getAttribute("aria-label") == "Question",
(el) => `** ${el.innerText.replace("\n", "")}`,
],
[
"[aria-label='option value']",
(el) => el.getAttribute("aria-label") == "option value",
(el) => el.value,
],
];
var cssSelector = template.map(t => t[0]).join(",");
var elArray = Array.from(document.querySelectorAll(cssSelector));
elArray.map(el =>
template
.map(t => t[1](el) ? t[2](el) : null)
.filter(Boolean)
).flat().join("\n");
And the result will be like this
* WHO IS DA BEST?
** Nama kamu
** Bidang kamu
Event Director
Funding and Business Project
General Manager
Graphic Expert
HRD
Logistic and Acomodation
Media and Content Management
Public Relations
Research and Education
Secretary
Technology and Data
Treasury
[...]