mirror of
https://invent.kde.org/network/falkon.git
synced 2024-12-20 02:36:34 +01:00
Fix form detection for password managerä
Original Author: Davide Signed-off-by: Juraj Oravec <jurajoravec@mailo.com>
This commit is contained in:
parent
563f81f5cf
commit
27c59ed16a
@ -74,31 +74,37 @@ QString Scripts::setupWebChannel()
|
|||||||
QString Scripts::setupFormObserver()
|
QString Scripts::setupFormObserver()
|
||||||
{
|
{
|
||||||
QString source = QL1S("(function() {"
|
QString source = QL1S("(function() {"
|
||||||
"function findUsername(inputs) {"
|
" let eFormsOld = [],"
|
||||||
" var usernameNames = ['user', 'name', 'login'];"
|
" eFormsDone = [];"
|
||||||
" for (var i = 0; i < usernameNames.length; ++i) {"
|
|
||||||
" for (var j = 0; j < inputs.length; ++j)"
|
|
||||||
" if (inputs[j].type == 'text' && inputs[j].value.length && inputs[j].name.indexOf(usernameNames[i]) != -1)"
|
|
||||||
" return inputs[j].value;"
|
|
||||||
" }"
|
|
||||||
" for (var i = 0; i < inputs.length; ++i)"
|
|
||||||
" if (inputs[i].type == 'text' && inputs[i].value.length)"
|
|
||||||
" return inputs[i].value;"
|
|
||||||
" for (var i = 0; i < inputs.length; ++i)"
|
|
||||||
" if (inputs[i].type == 'email' && inputs[i].value.length)"
|
|
||||||
" return inputs[i].value;"
|
|
||||||
" return '';"
|
|
||||||
"}"
|
|
||||||
""
|
""
|
||||||
"function registerForm(form) {"
|
" function findUsername(inputs) {"
|
||||||
" form.addEventListener('submit', function() {"
|
" let usernameNames = ['user', 'name', 'login'];"
|
||||||
" var form = this;"
|
""
|
||||||
" var data = '';"
|
" for (let i = 0; i < usernameNames.length; ++i) {"
|
||||||
" var password = '';"
|
" for (let j = 0; j < inputs.length; ++j)"
|
||||||
" var inputs = form.getElementsByTagName('input');"
|
" if (inputs[j].type == 'text' && inputs[j].value.length && inputs[j].name.indexOf(usernameNames[i]) != -1)"
|
||||||
" for (var i = 0; i < inputs.length; ++i) {"
|
" return inputs[j].value;"
|
||||||
" var input = inputs[i];"
|
" }"
|
||||||
" var type = input.type.toLowerCase();"
|
""
|
||||||
|
" for (let i = 0; i < inputs.length; ++i)"
|
||||||
|
" if (inputs[i].type == 'text' && inputs[i].value.length)"
|
||||||
|
" return inputs[i].value;"
|
||||||
|
""
|
||||||
|
" for (let i = 0; i < inputs.length; ++i)"
|
||||||
|
" if (inputs[i].type == 'email' && inputs[i].value.length)"
|
||||||
|
" return inputs[i].value;"
|
||||||
|
""
|
||||||
|
" return '';"
|
||||||
|
" }"
|
||||||
|
""
|
||||||
|
" function processForm(eForm) {"
|
||||||
|
" let data = '';"
|
||||||
|
" let password = '';"
|
||||||
|
" let inputs = eForm.getElementsByTagName('input');"
|
||||||
|
""
|
||||||
|
" for (let i = 0; i < inputs.length; ++i) {"
|
||||||
|
" let input = inputs[i];"
|
||||||
|
" let type = input.type.toLowerCase();"
|
||||||
" if (type != 'text' && type != 'password' && type != 'email')"
|
" if (type != 'text' && type != 'password' && type != 'email')"
|
||||||
" continue;"
|
" continue;"
|
||||||
" if (!password && type == 'password')"
|
" if (!password && type == 'password')"
|
||||||
@ -108,28 +114,59 @@ QString Scripts::setupFormObserver()
|
|||||||
" data += encodeURIComponent(input.value);"
|
" data += encodeURIComponent(input.value);"
|
||||||
" data += '&';"
|
" data += '&';"
|
||||||
" }"
|
" }"
|
||||||
|
""
|
||||||
" if (!password)"
|
" if (!password)"
|
||||||
" return;"
|
" return;"
|
||||||
|
""
|
||||||
|
" if (eFormsDone.every(e => e != eForm)) {"
|
||||||
|
" eFormsDone.push(eForm);"
|
||||||
|
" } else {"
|
||||||
|
" return;"
|
||||||
|
" }"
|
||||||
|
""
|
||||||
" data = data.substring(0, data.length - 1);"
|
" data = data.substring(0, data.length - 1);"
|
||||||
" var url = window.location.href;"
|
" let url = window.location.href;"
|
||||||
" var username = findUsername(inputs);"
|
" let username = findUsername(inputs);"
|
||||||
" external.autoFill.formSubmitted(url, username, password, data);"
|
" external.autoFill.formSubmitted(url, username, password, data);"
|
||||||
" }, true);"
|
" }"
|
||||||
"}"
|
|
||||||
""
|
""
|
||||||
"if (!document.documentElement) return;"
|
" function undoForm(eForm) {"
|
||||||
|
" let i = eFormsDone.indexOf(eForm);"
|
||||||
""
|
""
|
||||||
"for (var i = 0; i < document.forms.length; ++i)"
|
" if (i >= 0) {"
|
||||||
" registerForm(document.forms[i]);"
|
" eFormsDone.splice(i, 1);"
|
||||||
|
" }"
|
||||||
|
" }"
|
||||||
""
|
""
|
||||||
"var observer = new MutationObserver(function(mutations) {"
|
" function registerForm(eForm) {"
|
||||||
" for (var mutation of mutations)"
|
" let eInputs = eForm.getElementsByTagName('input');"
|
||||||
" for (var node of mutation.addedNodes)"
|
|
||||||
" if (node.tagName && node.tagName.toLowerCase() == 'form')"
|
|
||||||
" registerForm(node);"
|
|
||||||
"});"
|
|
||||||
"observer.observe(document.documentElement, { childList: true, subtree: true });"
|
|
||||||
""
|
""
|
||||||
|
" eForm.addEventListener('submit', () => processForm(eForm), true);"
|
||||||
|
""
|
||||||
|
" for (let eInput of eInputs) {"
|
||||||
|
" let type = eInput.type.toLowerCase();"
|
||||||
|
" "
|
||||||
|
" if (type == 'password') {"
|
||||||
|
" eInput.addEventListener('blur', () => processForm(eForm), true);"
|
||||||
|
" eInput.addEventListener('input', () => undoForm(eForm), true);"
|
||||||
|
" eInput.addEventListener('keydown', () => event.keyCode === 13 && processForm(eForm), true);"
|
||||||
|
" }"
|
||||||
|
" }"
|
||||||
|
" }"
|
||||||
|
""
|
||||||
|
" setInterval(() => {"
|
||||||
|
" try {"
|
||||||
|
" let eFormsNew = Array.from(document.forms);"
|
||||||
|
""
|
||||||
|
" for (let eFormNew of eFormsNew) {"
|
||||||
|
" if (eFormsOld.every(e => e != eFormNew)) {"
|
||||||
|
" eFormsOld.push(eFormNew);"
|
||||||
|
" registerForm(eFormNew);"
|
||||||
|
" }"
|
||||||
|
" }"
|
||||||
|
""
|
||||||
|
" } catch (e) {}"
|
||||||
|
" }, 100);"
|
||||||
"})()");
|
"})()");
|
||||||
|
|
||||||
return source;
|
return source;
|
||||||
|
Loading…
Reference in New Issue
Block a user