Revision bac96457
Added by koszko over 1 year ago
src/google_forms.js | ||
---|---|---|
4 | 4 |
* (Incomplete) Fix for Google Forms |
5 | 5 |
* |
6 | 6 |
* Copyright © 2021 jahoti <jahoti@tilde.team> |
7 |
* Copyright 2022 Wojtek Kosior <koszko@koszko.org> |
|
7 | 8 |
* |
8 | 9 |
* Licensed under the Apache License, Version 2.0 (the "License"); |
9 | 10 |
* you may not use this file except in compliance with the License. |
... | ... | |
16 | 17 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
17 | 18 |
* See the License for the specific language governing permissions and |
18 | 19 |
* limitations under the License. |
20 |
* |
|
21 |
* I, Wojtek Kosior, thereby promise not to sue for violation of this file's |
|
22 |
* license. Although I request that you do not make use of this code in a way |
|
23 |
* incompliant with the license, I am not going to enforce this in court. |
|
19 | 24 |
*/ |
20 | 25 |
|
21 | 26 |
var form = document.forms[0]; |
... | ... | |
24 | 29 |
var name = 'entry.' + data[0][4][0][0]; |
25 | 30 |
var input = div.querySelector('input'); |
26 | 31 |
|
32 |
if (!input) { |
|
33 |
console.error(`cannot enable input ${name}`, div); |
|
34 |
continue; |
|
35 |
} |
|
36 |
|
|
27 | 37 |
if (input.name === name + '_sentinel') { // Radio |
28 |
for (input of div.querySelectorAll('.appsMaterialWizToggleRadiogroupElContainer')) {
|
|
29 |
div = document.createElement('input');
|
|
30 |
div.type = 'radio';
|
|
31 |
div.name = name;
|
|
32 |
div.value = input.nextElementSibling.innerText.trim();
|
|
33 |
input.parentNode.replaceChild(div, input);
|
|
38 |
for (const input_div of div.querySelectorAll('.appsMaterialWizToggleRadiogroupEl')) {
|
|
39 |
const new_radio = document.createElement('input');
|
|
40 |
new_radio.type = 'radio';
|
|
41 |
new_radio.name = name;
|
|
42 |
new_radio.value = input_div.getAttribute("data-value");
|
|
43 |
input_div.replaceWith(new_radio);
|
|
34 | 44 |
} |
35 | 45 |
} else { |
36 | 46 |
input.removeAttribute('disabled'); |
... | ... | |
51 | 61 |
form.submit(); |
52 | 62 |
} |
53 | 63 |
|
54 |
for (div of document.querySelectorAll('.freebirdFormviewerViewNavigationNoSubmitButton')) { |
|
55 |
input = document.createElement('button'); |
|
64 |
const submit_selector = ".freebirdFormviewerViewNavigationSubmitButton"; |
|
65 |
const next_selector = ".freebirdFormviewerViewNavigationNoSubmitButton"; |
|
66 |
for (const but_div of document.querySelectorAll(submit_selector)) |
|
67 |
but_div.addEventListener("click", () => form.submit()); |
|
56 | 68 |
|
57 |
data = div.innerText.trim(); |
|
58 |
input.innerText = data; |
|
59 |
if (data.toLowerCase() === 'next') |
|
60 |
input.onclick = goToNext; |
|
61 |
else if (data.toLowerCase() === 'submit') |
|
62 |
input.type = 'submit'; |
|
63 |
div.parentNode.replaceChild(input, div); |
|
64 |
} |
|
69 |
for (const but_div of document.querySelectorAll(next_selector)) |
|
70 |
but_div.addEventListener("click", goToNext); |
|
65 | 71 |
|
66 |
// TODO: back, instate previous entries |
|
72 |
// TODO: back, instate previous entries, fix form parts that still don't work |
Also available in: Unified diff
improve some of the fixes and add sample URLs for testing