diff options
author | Allan Wang <me@allanwang.ca> | 2018-12-24 01:47:03 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-12-24 01:47:03 -0500 |
commit | 697d01882ba8b1dbb85484ba3bf6e810e32448fc (patch) | |
tree | f59d2407ffbd724200e3c79eb366a8da1efe0829 /app/src/main/kotlin/com/pitchedapps/frost/injectors | |
parent | c45b30e28f451699f3be828a1201260ed27e321e (diff) | |
download | frost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.tar.gz frost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.tar.bz2 frost-697d01882ba8b1dbb85484ba3bf6e810e32448fc.zip |
Enhancement/ktlint (#1259)
* Add spotless
* Reformat code
* Apply license header
* Add remaining license headers
Diffstat (limited to 'app/src/main/kotlin/com/pitchedapps/frost/injectors')
5 files changed, 121 insertions, 34 deletions
diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt index 033e482f..de19f99c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssAssets.kt @@ -1,14 +1,35 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.injectors import android.graphics.Color import android.webkit.WebView import ca.allanwang.kau.kotlin.lazyContext -import ca.allanwang.kau.utils.* +import ca.allanwang.kau.utils.adjustAlpha +import ca.allanwang.kau.utils.colorToBackground +import ca.allanwang.kau.utils.colorToForeground +import ca.allanwang.kau.utils.toRgbaString +import ca.allanwang.kau.utils.use +import ca.allanwang.kau.utils.withAlpha import com.pitchedapps.frost.utils.L import com.pitchedapps.frost.utils.Prefs import java.io.BufferedReader import java.io.FileNotFoundException -import java.util.* +import java.util.Locale /** * Created by Allan Wang on 2017-05-31. @@ -32,17 +53,17 @@ enum class CssAssets(val folder: String = "themes") : InjectorContract { val bb = Prefs.bgColor.colorToForeground(0.35f) content = content - .replace("\$T\$", Prefs.textColor.toRgbaString()) - .replace("\$TT\$", Prefs.textColor.colorToBackground(0.05f).toRgbaString()) - .replace("\$A\$", Prefs.accentColor.toRgbaString()) - .replace("\$B\$", Prefs.bgColor.toRgbaString()) - .replace("\$BT\$", bt) - .replace("\$BBT\$", bb.withAlpha(51).toRgbaString()) - .replace("\$O\$", Prefs.bgColor.withAlpha(255).toRgbaString()) - .replace("\$OO\$", bb.withAlpha(255).toRgbaString()) - .replace("\$D\$", Prefs.textColor.adjustAlpha(0.3f).toRgbaString()) - .replace("\$TI\$", bb.withAlpha(60).toRgbaString()) - .replace("\$C\$", bt) + .replace("\$T\$", Prefs.textColor.toRgbaString()) + .replace("\$TT\$", Prefs.textColor.colorToBackground(0.05f).toRgbaString()) + .replace("\$A\$", Prefs.accentColor.toRgbaString()) + .replace("\$B\$", Prefs.bgColor.toRgbaString()) + .replace("\$BT\$", bt) + .replace("\$BBT\$", bb.withAlpha(51).toRgbaString()) + .replace("\$O\$", Prefs.bgColor.withAlpha(255).toRgbaString()) + .replace("\$OO\$", bb.withAlpha(255).toRgbaString()) + .replace("\$D\$", Prefs.textColor.adjustAlpha(0.3f).toRgbaString()) + .replace("\$TI\$", bb.withAlpha(60).toRgbaString()) + .replace("\$C\$", bt) } JsBuilder().css(content).build() } catch (e: FileNotFoundException) { @@ -58,5 +79,4 @@ enum class CssAssets(val folder: String = "themes") : InjectorContract { fun reset() { injector.invalidate() } - } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssHider.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssHider.kt index 5444fad8..7da6295f 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssHider.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssHider.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.injectors import android.webkit.WebView @@ -9,10 +25,14 @@ import android.webkit.WebView */ enum class CssHider(vararg val items: String) : InjectorContract { CORE("[data-sigil=m_login_upsell]", "[role=progressbar]"), - HEADER("#header", "#mJewelNav", "[data-sigil=MTopBlueBarHeader]", - "#header-notices", "[data-sigil*=m-promo-jewel-header]"), - ADS("article[data-xt*=sponsor]", - "article[data-store*=sponsor]"), + HEADER( + "#header", "#mJewelNav", "[data-sigil=MTopBlueBarHeader]", + "#header-notices", "[data-sigil*=m-promo-jewel-header]" + ), + ADS( + "article[data-xt*=sponsor]", + "article[data-store*=sponsor]" + ), PEOPLE_YOU_MAY_KNOW("article._d2r"), SUGGESTED_GROUPS("article[data-ft*=\"ei\":]"), COMPOSER("#MComposer"), @@ -22,11 +42,10 @@ enum class CssHider(vararg val items: String) : InjectorContract { val injector: JsInjector by lazy { JsBuilder().css("${items.joinToString(separator = ",")}{display:none !important}") - .single(name).build() + .single(name).build() } override fun inject(webView: WebView, callback: (() -> Unit)?) { injector.inject(webView, callback) } - -}
\ No newline at end of file +} diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsActions.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsActions.kt index 1ab00153..e64d4faa 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsActions.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsActions.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.injectors import android.webkit.WebView @@ -27,10 +43,9 @@ enum class JsActions(body: String) : InjectorContract { val function = "(function(){$body})();" override fun inject(webView: WebView, callback: (() -> Unit)?) = - JsInjector(function).inject(webView, callback) - + JsInjector(function).inject(webView, callback) } @Suppress("NOTHING_TO_INLINE") private inline fun clickBySelector(selector: String): String = - """document.querySelector("$selector").click()"""
\ No newline at end of file + """document.querySelector("$selector").click()""" diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt index 980481a4..0dccc751 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsAssets.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.injectors import android.webkit.WebView @@ -5,7 +21,7 @@ import ca.allanwang.kau.kotlin.lazyContext import com.pitchedapps.frost.utils.L import java.io.BufferedReader import java.io.FileNotFoundException -import java.util.* +import java.util.Locale /** * Created by Allan Wang on 2017-05-31. @@ -31,5 +47,4 @@ enum class JsAssets : InjectorContract { override fun inject(webView: WebView, callback: (() -> Unit)?) { injector(webView.context).inject(webView, callback) } - } diff --git a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt index acda2d9b..8ae3a2f4 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/JsInjector.kt @@ -1,3 +1,19 @@ +/* + * Copyright 2018 Allan Wang + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ package com.pitchedapps.frost.injectors import android.webkit.WebView @@ -8,7 +24,7 @@ import io.reactivex.android.schedulers.AndroidSchedulers import io.reactivex.disposables.Disposable import io.reactivex.subjects.SingleSubject import org.apache.commons.text.StringEscapeUtils -import java.util.* +import java.util.Locale class JsBuilder { private val css = StringBuilder() @@ -90,10 +106,10 @@ fun WebView.jsInject(vararg injectors: InjectorContract, callback: ((Int) -> Uni } val observables = Array(validInjectors.size) { SingleSubject.create<Unit>() } val disposable = Single.zip<Unit, Int>(observables.asList()) { it.size } - .observeOn(AndroidSchedulers.mainThread()) - .subscribe { res, _ -> - callback(res) - } + .observeOn(AndroidSchedulers.mainThread()) + .subscribe { res, _ -> + callback(res) + } (0 until validInjectors.size).forEach { i -> validInjectors[i].inject(this) { observables[i].onSuccess(Unit) @@ -102,8 +118,10 @@ fun WebView.jsInject(vararg injectors: InjectorContract, callback: ((Int) -> Uni return disposable } -fun FrostWebViewClient.jsInject(vararg injectors: InjectorContract, - callback: ((Int) -> Unit)? = null) = web.jsInject(*injectors, callback = callback) +fun FrostWebViewClient.jsInject( + vararg injectors: InjectorContract, + callback: ((Int) -> Unit)? = null +) = web.jsInject(*injectors, callback = callback) /** * Wrapper class to convert a function into an injector @@ -112,4 +130,4 @@ class JsInjector(val function: String) : InjectorContract { override fun inject(webView: WebView, callback: (() -> Unit)?) { webView.evaluateJavascript(function) { callback?.invoke() } } -}
\ No newline at end of file +} |