Last active
September 20, 2020 07:49
-
-
Save eeeschwartz/6086efb174d6dc076fc6 to your computer and use it in GitHub Desktop.
Extract questions from google form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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
What is the use of this js code