aboutsummaryrefslogtreecommitdiff
path: root/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt
diff options
context:
space:
mode:
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt')
-rw-r--r--app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt32
1 files changed, 32 insertions, 0 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt
new file mode 100644
index 00000000..2bf53d2e
--- /dev/null
+++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt
@@ -0,0 +1,32 @@
+package com.pitchedapps.frost.injectors
+
+import android.webkit.WebView
+import com.pitchedapps.frost.utils.L
+
+/**
+ * Created by Allan Wang on 2017-05-31.
+ * Mapping of the available assets
+ * The enum name must match the css file name
+ * //TODO add folder mapping using Prefs
+ */
+enum class JsAssets {
+ MENU
+ ;
+
+ var file = "${name.toLowerCase()}.min.js"
+ var injector: JsInjector? = null
+
+ fun inject(webView: WebView, callback: ((String) -> Unit)?) {
+ if (injector == null) {
+ val content = webView.context.assets.open("js/$file").bufferedReader().use { it.readText() }
+ injector = JsBuilder().js(content).build()
+ }
+ injector!!.inject(webView, callback)
+ L.v("JS ${injector!!.function}")
+ }
+
+ fun reset() {
+ injector = null
+ }
+
+} \ No newline at end of file