Skip to content

Commit

Permalink
Create Google-Forms-Quiz-Resolver.user.js
Browse files Browse the repository at this point in the history
  • Loading branch information
zerodytrash authored Apr 4, 2021
1 parent 71132c8 commit e33e156
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions Google-Forms-Quiz-Resolver.user.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// ==UserScript==
// @name Google Forms Quiz Resolver
// @namespace http://tampermonkey.net/
// @version 0.1
// @description This script tries to extract exact answer conditions from Google Forms and solve them
// @author You
// @match https://docs.google.com/forms/*
// @grant none
// @run-at document-end
// ==/UserScript==

(function() {
'use strict';

// skip form if already filled by url params
if(location.href.indexOf("?entry.") > 0) return;

var inputAreas = document.querySelectorAll("div[data-params]");
var urlPrefillParams = new URLSearchParams();

inputAreas.forEach((inputArea) => {
try {

var areaParams = inputArea.getAttribute("data-params");
var decodedAreaParams = JSON.parse("[" + areaParams.substr(areaParams.indexOf("["), areaParams.length));
var questionParams = decodedAreaParams[0][4][0];
var questionEntryId = questionParams[0];
var validationParams = questionParams[4];

// if validation disabled
if(validationParams.length === 0) return;

var validationRule = validationParams[0];
var valueToFill = null;

// type: number && match: exact
if(validationRule[0] === 1 && validationRule[1] === 5) {
valueToFill = validationRule[2][0];
}

if(valueToFill !== null) urlPrefillParams.set("entry." + questionEntryId, valueToFill);

} catch(ex) {
console.error("Param decoding failed", ex, inputArea);
}
});

if(Array.from(urlPrefillParams).length > 0) {
if(confirm("Found " + Array.from(urlPrefillParams).length + " exact values in form validation. Prefill form?")) {
location.search = urlPrefillParams;
}
}
})();

0 comments on commit e33e156

Please sign in to comment.