From bac96457a5b53a3f5fa5857e108e9e32515bb02b Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Mon, 21 Feb 2022 14:03:11 +0100 Subject: improve some of the fixes and add sample URLs for testing --- src/google_forms.js | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) (limited to 'src/google_forms.js') diff --git a/src/google_forms.js b/src/google_forms.js index 5d8826d..54c1a04 100644 --- a/src/google_forms.js +++ b/src/google_forms.js @@ -4,6 +4,7 @@ * (Incomplete) Fix for Google Forms * * Copyright © 2021 jahoti + * Copyright 2022 Wojtek Kosior * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +17,10 @@ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. + * + * I, Wojtek Kosior, thereby promise not to sue for violation of this file's + * license. Although I request that you do not make use of this code in a way + * incompliant with the license, I am not going to enforce this in court. */ var form = document.forms[0]; @@ -24,13 +29,18 @@ for (let div of form.querySelectorAll('div[data-params]')) { var name = 'entry.' + data[0][4][0][0]; var input = div.querySelector('input'); + if (!input) { + console.error(`cannot enable input ${name}`, div); + continue; + } + if (input.name === name + '_sentinel') { // Radio - for (input of div.querySelectorAll('.appsMaterialWizToggleRadiogroupElContainer')) { - div = document.createElement('input'); - div.type = 'radio'; - div.name = name; - div.value = input.nextElementSibling.innerText.trim(); - input.parentNode.replaceChild(div, input); + for (const input_div of div.querySelectorAll('.appsMaterialWizToggleRadiogroupEl')) { + const new_radio = document.createElement('input'); + new_radio.type = 'radio'; + new_radio.name = name; + new_radio.value = input_div.getAttribute("data-value"); + input_div.replaceWith(new_radio); } } else { input.removeAttribute('disabled'); @@ -51,16 +61,12 @@ function goToNext() form.submit(); } -for (div of document.querySelectorAll('.freebirdFormviewerViewNavigationNoSubmitButton')) { - input = document.createElement('button'); +const submit_selector = ".freebirdFormviewerViewNavigationSubmitButton"; +const next_selector = ".freebirdFormviewerViewNavigationNoSubmitButton"; +for (const but_div of document.querySelectorAll(submit_selector)) + but_div.addEventListener("click", () => form.submit()); - data = div.innerText.trim(); - input.innerText = data; - if (data.toLowerCase() === 'next') - input.onclick = goToNext; - else if (data.toLowerCase() === 'submit') - input.type = 'submit'; - div.parentNode.replaceChild(input, div); -} +for (const but_div of document.querySelectorAll(next_selector)) + but_div.addEventListener("click", goToNext); -// TODO: back, instate previous entries +// TODO: back, instate previous entries, fix form parts that still don't work -- cgit v1.2.3