Google Forms Quiz Solver

This script tries to extract exact answer conditions from Google Forms and solve them

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

Advertisement:

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

Advertisement:

// ==UserScript==
// @name         Google Forms Quiz Solver
// @namespace    https://zerody.one
// @version      0.2
// @description  This script tries to extract exact answer conditions from Google Forms and solve them
// @author       ZerodyOne (https://github.com/zerodytrash/)
// @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: equal to
            if(validationRule[0] === 1 && validationRule[1] === 5) {
                valueToFill = validationRule[2][0];
            }

            // type: text && match: contains
            if(validationRule[0] === 2 && validationRule[1] === 100) {
                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;
        }
    }
})();