Project

General

Profile

Download (2.04 KB) Statistics
| Branch: | Revision:

hydrilla-fixes-bundle / src / google_forms.js @ e24c60dd

1
/**
2
 * SPDX-License-Identifier: Apache-2.0
3
 *
4
 * (Incomplete) Fix for Google Forms
5
 *
6
 * Copyright © 2021 jahoti <jahoti@tilde.team>
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *    http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

    
21
var form = document.forms[0];
22
for (let div of form.querySelectorAll('div[data-params]')) {
23
    var data = JSON.parse('[' + div.dataset.params.substring(4));
24
    var name = 'entry.' + data[0][4][0][0];
25
    var input = div.querySelector('input');
26

    
27
    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);
34
	}
35
    } else {
36
	input.removeAttribute('disabled');
37
	input.name = name;
38
    }
39
}
40

    
41
for (div of document.querySelectorAll('.quantumWizTextinputPaperinputPlaceholder'))
42
    div.remove();
43

    
44
function goToNext()
45
{
46
    var next = document.createElement('input');
47
    next.type = 'hidden';
48
    next.name = 'continue';
49
    next.value = '1';
50
    form.appendChild(next);
51
    form.submit();
52
}
53

    
54
for (div of document.querySelectorAll('.freebirdFormviewerViewNavigationNoSubmitButton')) {
55
    input = document.createElement('button');
56

    
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
}
65

    
66
// TODO: back, instate previous entries
(7-7/22)