aboutsummaryrefslogtreecommitdiff
path: root/src/wallet/wallet.cpp
blob: 5023ea46b2496bcb176b8c21129832571206616a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * This file is part of smolbote. It's copyrighted by the contributors recorded
 * in the version control history of the file, available from its original
 * location: https://neueland.iserlohn-fortress.net/gitea/aqua/smolbote
 *
 * SPDX-License-Identifier: GPL-3.0
 */

#include "wallet.h"
#include <QWebEngineView>
#include <QWebEngineScript>

void Wallet::autocompleteForm(QWebEngineView *view)
{
    const auto findFormFunction = QLatin1String("index = undefined; for(var i = 0; i < document.forms.length; ++i) { if(document.forms[i].autocomplete) { index = i } }; index");

    view->page()->runJavaScript(findFormFunction, QWebEngineScript::ApplicationWorld, [view](const QVariant &v) {
        if(!v.isNull()) {
            const QString username = "test-username";
            const QString password = "test-password";

            auto autofillFunction = QString("inputs = document.forms[%1].getElementsByTagName('input');"
                                            "for(var i = 0; i < inputs.length; ++i) {"
                                            "  if(inputs[i].type == 'username') { inputs[i].value='username' }"
                                            "  else if(inputs[i].type == 'email') { inputs[i].value='%2' }"
                                            "  else if(inputs[i].type == 'password') { inputs[i].value='%3' }"
                                            "  else { inputs[i].value=inputs[i].type }"
                                            "}")
                                        .arg(v.toString(), username, password);
            // TODO
            // for page->url() get list of pairs type = value
            view->page()->runJavaScript(autofillFunction, QWebEngineScript::ApplicationWorld);
        }
    });
}