blob: e7a9df5a69f3e6ca1e9ac2f584c781a9f9b3f7cb (
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
|
package com.pitchedapps.frost.injectors
import android.webkit.WebView
/**
* Created by Allan Wang on 2017-05-31.
*/
class JsInjector {
private val builder = StringBuilder()
init {
builder.append("javascript:(function(){")
}
private fun getElementById(id: String) = "document.getElementById(\"$id\")"
private fun hideElementById(id: String) {
builder.append(getElementById(id)).append(".style.display=\"none\";")
}
fun hideElementById(vararg ids: String) {
ids.forEach { hideElementById(it) }
}
fun build() = builder.toString() + "})()"
fun inject(webView: WebView) {
webView.loadUrl(build())
}
override fun toString() = build()
}
|