Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Extract questions from google form
<a href="javascript:void(function () {
var jsCode = document.createElement('script');
jsCode.setAttribute('src', 'https://gist.githubusercontent.com/eeeschwartz/6086efb174d6dc076fc6/raw/main.js');
document.body.appendChild(jsCode);
}())">Extract Qs</a>
(function(){
var body = document.getElementsByTagName('body')[0];
var html = '<div id="extracted-container" style="position:absolute; left: 0; top: 0; border: 1px solid #CCC; background: white; padding: 0.4em"><ul class="extracted-questions"></ul></div>'
body.insertAdjacentHTML('afterBegin', html);
var container = document.getElementById('extracted-container');
var extractedQuestions = container.getElementsByClassName('extracted-questions')[0];
var gQuestions = document.getElementsByClassName('ss-form-entry');
Array.prototype.forEach.call(gQuestions, function(question) {
if (question.getElementsByClassName('ss-q-title')[0]) {
var label = question.getElementsByClassName('ss-q-title')[0].textContent;
var input = question.getElementsByTagName('input')[0] || question.getElementsByTagName('textarea')[0];
var attr = [];
//if (question.getElementsByClassName('required-message').length > 0) { attr.push('required') }
if (input && input.type) { attr.push(input.type) }
if (attr.length > 0) { label += (' (' + attr.join(' ') + ')') }
extractedQuestions.insertAdjacentHTML('beforeEnd', '<li>' + label + '</li>');
} else {
// pluck section title
}
});
extractedQuestions.insertAdjacentHTML('beforeBegin', '<div class="extracted-close"><button style="float:right">Close</button></div>');
container.getElementsByClassName('extracted-close')[0].onclick = function(el) {
body.removeChild(container);
}
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment