From c9ee5d79df4cb1baab4357fc11c13a4514af2c6f Mon Sep 17 00:00:00 2001 From: Allan Wang Date: Thu, 22 Jun 2017 16:24:12 -0700 Subject: Add ad block --- .../main/kotlin/com/pitchedapps/frost/SettingsActivity.kt | 8 +++++--- .../main/kotlin/com/pitchedapps/frost/injectors/CssHider.kt | 12 +++++++++--- app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt | 2 ++ .../kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt | 2 ++ app/src/main/res/values/strings_preferences | 4 +++- 5 files changed, 21 insertions(+), 7 deletions(-) (limited to 'app/src') diff --git a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt index ca823513..cde23ebc 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/SettingsActivity.kt @@ -118,6 +118,10 @@ class SettingsActivity : KPrefActivity() { checkbox(R.string.suggested_friends, { Prefs.showSuggestedFriends }, { Prefs.showSuggestedFriends = it }) { descRes = R.string.suggested_friends_desc } + + checkbox(R.string.facebook_ads, { Prefs.showFacebookAds }, { Prefs.showFacebookAds = it }) { + descRes = R.string.facebook_ads_desc + } } @@ -153,10 +157,8 @@ class SettingsActivity : KPrefActivity() { this@SettingsActivity.materialDialogThemed { title(R.string.notification_keywords) customView(keywordView, false) - canceledOnTouchOutside(false) + dismissListener { keywordView.save() } positiveText(R.string.kau_done) - negativeText(R.string.kau_cancel) - onPositive { _, _ -> keywordView.save() } } true } 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 72279ee3..ba0bdaac 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssHider.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/injectors/CssHider.kt @@ -1,20 +1,26 @@ package com.pitchedapps.frost.injectors import android.webkit.WebView +import com.pitchedapps.frost.utils.L /** * Created by Allan Wang on 2017-05-31. */ enum class CssHider(vararg val items: String) : InjectorContract { - CORE("[data-sigil=\"m_login_upsell\"]"), - HEADER("#header[data-sigil=\"MTopBlueBarHeader\"]", "#header-notices", "[data-sigil*=\"m-promo-jewel-header\"]"), - ADS("[data-xt*=\"is_sponsored.1\"]") + CORE("[data-sigil=m_login_upsell]"), + HEADER("#header[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") ; val injector: JsInjector by lazy { JsBuilder().css("${items.joinToString(separator = ",")}{display:none!important}").build() } override fun inject(webView: WebView, callback: ((String) -> Unit)?) { injector.inject(webView, callback) + L.d(injector.function) } } \ No newline at end of file diff --git a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt index 428d0c30..9128c42b 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/utils/Prefs.kt @@ -66,6 +66,8 @@ object Prefs : KPref() { var showSuggestedFriends: Boolean by kpref("suggested_friends_feed", true) + var showFacebookAds: Boolean by kpref("facebook_ads", true) + var animate: Boolean by kpref("fancy_animations", true) var notificationKeywords: StringSet by kpref("notification_keywords", mutableSetOf()) diff --git a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt index 8b1eca1e..ebea533c 100644 --- a/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt +++ b/app/src/main/kotlin/com/pitchedapps/frost/web/FrostWebViewClient.kt @@ -52,6 +52,8 @@ open class FrostWebViewClient(val webCore: FrostWebViewCore) : WebViewClient() { } view.jsInject(JsActions.LOGIN_CHECK, CssAssets.ROUND_ICONS.maybe(Prefs.showRoundedIcons), + CssHider.PEOPLE_YOU_MAY_KNOW.maybe(!Prefs.showSuggestedFriends), + CssHider.ADS.maybe(!Prefs.showFacebookAds), JsAssets.HEADER_BADGES.maybe(webCore.baseEnum != null)) onPageFinishedActions(url) } diff --git a/app/src/main/res/values/strings_preferences b/app/src/main/res/values/strings_preferences index 2aad590f..08603ab4 100644 --- a/app/src/main/res/values/strings_preferences +++ b/app/src/main/res/values/strings_preferences @@ -16,7 +16,9 @@ Base Customization Feed Customization Suggested Friends - Show suggested friends in the feed + Show "People You May Know" in the feed + Facebook Ads + Show native Facebook ads Notification Frequency Keywords -- cgit v1.2.3