diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/docs-google-com-fix-forms/google_forms.js | 43 | ||||
-rw-r--r-- | src/docs-google-com-fix-forms/index.json | 4 |
2 files changed, 39 insertions, 8 deletions
diff --git a/src/docs-google-com-fix-forms/google_forms.js b/src/docs-google-com-fix-forms/google_forms.js index 2abf3fa..4652426 100644 --- a/src/docs-google-com-fix-forms/google_forms.js +++ b/src/docs-google-com-fix-forms/google_forms.js @@ -5,6 +5,7 @@ * * Copyright © 2021 jahoti <jahoti@tilde.team> * Copyright 2022 Wojtek Kosior <koszko@koszko.org> + * Copytight 2022 Jacob K * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,9 +27,20 @@ var form = document.forms[0]; /* Fix form fields. */ -for (let div of form.querySelectorAll('div[data-params]')) { - var data = JSON.parse('[' + div.dataset.params.substring(4)); - var name = 'entry.' + data[0][4][0][0]; +for (let div of form.querySelectorAll('div[data-params], div.geS5n.AgroKb.oQYVNd')) { + /* + * The selector, "div.geS5n.AgroKb.oQYVNd", is to catch email fields, which + * don't have a data-params attribute. + */ + if (div.dataset.params) { + const data = JSON.parse('[' + div.dataset.params.substring(4)); + var name = 'entry.' + data[0][4][0][0]; + } else if (div.className == "geS5n AgroKb oQYVNd") { + var name = "emailAddress"; + } else { + console.error(`Cannot enable input`, div); + continue; + } var input = div.querySelector('input, textarea'); if (!input) { @@ -45,6 +57,14 @@ for (let div of form.querySelectorAll('div[data-params]')) { new_radio.value = input_div.getAttribute("data-value"); input_div.replaceWith(new_radio); } + /* Handle checkboxes. */ + for (const input_div of div.querySelectorAll('[data-answer-value]')) { + const new_checkbox = document.createElement('input'); + new_checkbox.type = 'checkbox'; + new_checkbox.name = name; + new_checkbox.value = input_div.getAttribute("data-answer-value"); + input_div.replaceWith(new_checkbox); + } } else { input.removeAttribute('disabled'); input.name = name; @@ -78,6 +98,17 @@ function goToNext() for (const next_but of document.querySelectorAll('[jsname=OCpkoe]')) next_but.addEventListener("click", goToNext); -// TODO: -// * support "back" with instatiation of previous entries -// * find and fix form parts that still don't work (if any) +/* Remove no JavaScript warning (if any). */ +for (const warning of + document.querySelectorAll(".HB1eCd-X3SwIb-i8xkGf, noscript")) + warning.remove(); + +/* TODO: + * support "back" with instatiation of previous entries + * find and fix form parts that still don't work (if any) + * support dropdown inputs + * support "other" radio buttons and "other" checkbox buttons, in which the + user types text in addition to selecting the "other" box + * support reCAPTCHA integration + * support displaying public analytics ("viewanalytics" instead of "viewform") +*/ diff --git a/src/docs-google-com-fix-forms/index.json b/src/docs-google-com-fix-forms/index.json index ee70a15..c74688a 100644 --- a/src/docs-google-com-fix-forms/index.json +++ b/src/docs-google-com-fix-forms/index.json @@ -17,8 +17,8 @@ "identifier": "docs-google-com-fix-forms", "long_name": "Google Forms submission fix", "uuid": "23f51630-6118-4ef2-9709-2a1dba7ebb52", - "version": [2022, 3, 7], - "revision": 2, + "version": [2022, 8, 16], + "revision": 1, "description": "Enable filling and submitting of Google Forms without relying on site-served JavaScript.", "dependencies": [], "scripts": [{"file": "google_forms.js"}], |