diff options
author | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-01-11 14:08:41 +0200 |
---|---|---|
committer | Aqua-sama <aqua@iserlohn-fortress.net> | 2020-01-11 17:22:07 +0200 |
commit | 94144b358301b69639f96e4f674b876b99ffa26e (patch) | |
tree | a62e6980fa603c915d5481eda911888da3285b3e /src/wallet/wallet.cpp | |
parent | Code cleanup (diff) | |
download | smolbote-94144b358301b69639f96e4f674b876b99ffa26e.tar.xz |
Refactor WebViewContextMenu
- Remove KDE Wallet code
Diffstat (limited to 'src/wallet/wallet.cpp')
-rw-r--r-- | src/wallet/wallet.cpp | 41 |
1 files changed, 16 insertions, 25 deletions
diff --git a/src/wallet/wallet.cpp b/src/wallet/wallet.cpp index c795cf2..5023ea4 100644 --- a/src/wallet/wallet.cpp +++ b/src/wallet/wallet.cpp @@ -8,37 +8,28 @@ #include "wallet.h" #include <QWebEngineView> - -#ifdef PLASMA -#include <kwallet.h> -#endif +#include <QWebEngineScript> void Wallet::autocompleteForm(QWebEngineView *view) { -#ifdef PLASMA - const auto findFormFunction = QLatin1Literal("index = undefined; for(var i = 0; i < document.forms.length; ++i) { if(document.forms[i].autocomplete) { index = i } }; index"); - view->page()->runJavaScript(findFormFunction, [view](const QVariant &v) { + 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 == 'email') { inputs[i].value='%2' }" - " if(inputs[i].type == 'password') { inputs[i].value='%3' }" - "}"); - - auto *wallet = KWallet::Wallet::openWallet(KWallet::Wallet::LocalWallet(), view->window()->winId()); - if(wallet) { - wallet->setFolder("smolbote"); - QMap<QString, QString> map; - wallet->readMap(view->url().host(), map); - qDebug() << map; - - const auto username = map.firstKey(); - QString password; - wallet->readPassword(map.value(username), password); - view->page()->runJavaScript(autofillFunction.arg(v.toString(), username, password)); - } - delete wallet; + " 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); } }); -#endif } |