mirror of
https://github.com/AllanWang/Frost-for-Facebook.git
synced 2024-11-10 04:52:38 +01:00
Fix/adblock (#338)
* Rename none to no notifications * Add pgl adblock and adblock class * Add faq * Line spacing
This commit is contained in:
parent
952d4e41ef
commit
bd7da76b14
@ -1417,6 +1417,7 @@ goingplatinum.com
|
||||
goldstats.com
|
||||
google-analytics.com
|
||||
googleadservices.com
|
||||
googleads.g.doubleclick.net
|
||||
googlesyndication.com
|
||||
gostats.com
|
||||
gp.dejanews.com
|
||||
@ -1778,6 +1779,7 @@ pagerank-submitter.de
|
||||
pagerank-united.de
|
||||
pagerank4you.com
|
||||
pageranktop.com
|
||||
pagead2.googlesyndication.com
|
||||
parse.ly.invalid
|
||||
parsely.com
|
||||
partage-facile.com
|
||||
@ -2095,6 +2097,7 @@ targetnet.com
|
||||
targetpoint.com
|
||||
tatsumi-sys.jp
|
||||
tcads.net
|
||||
tpc.googlesyndication.com
|
||||
teads.tv
|
||||
techclicks.net
|
||||
teenrevenue.com
|
||||
|
2409
app/src/main/assets/pgl.yoyo.org.txt
Normal file
2409
app/src/main/assets/pgl.yoyo.org.txt
Normal file
File diff suppressed because it is too large
Load Diff
@ -16,6 +16,7 @@ import com.mikepenz.materialdrawer.util.AbstractDrawerImageLoader
|
||||
import com.mikepenz.materialdrawer.util.DrawerImageLoader
|
||||
import com.pitchedapps.frost.facebook.FbCookie
|
||||
import com.pitchedapps.frost.services.scheduleNotifications
|
||||
import com.pitchedapps.frost.utils.FrostPglAdBlock
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
import com.pitchedapps.frost.utils.Showcase
|
||||
@ -51,6 +52,7 @@ class FrostApp : Application() {
|
||||
Prefs.verboseLogging = false
|
||||
L.i("Begin Frost for Facebook")
|
||||
FbCookie()
|
||||
FrostPglAdBlock.init(this)
|
||||
if (Prefs.installDate == -1L) Prefs.installDate = System.currentTimeMillis()
|
||||
if (Prefs.identifier == -1) Prefs.identifier = Random().nextInt(Int.MAX_VALUE)
|
||||
Prefs.lastLaunch = System.currentTimeMillis()
|
||||
|
@ -24,7 +24,7 @@ fun SettingsActivity.getNotificationPrefs(): KPrefAdapterBuilder.() -> Unit = {
|
||||
|
||||
text(R.string.notification_frequency, { Prefs.notificationFreq }, { Prefs.notificationFreq = it }) {
|
||||
val options = longArrayOf(-1, 15, 30, 60, 120, 180, 300, 1440, 2880)
|
||||
val texts = options.map { minuteToText(it) }
|
||||
val texts = options.map { if (it <= 0) string(R.string.no_notifications) else minuteToText(it) }
|
||||
onClick = { _, _, item ->
|
||||
materialDialogThemed {
|
||||
title(R.string.notification_frequency)
|
||||
|
43
app/src/main/kotlin/com/pitchedapps/frost/utils/AdBlocker.kt
Normal file
43
app/src/main/kotlin/com/pitchedapps/frost/utils/AdBlocker.kt
Normal file
@ -0,0 +1,43 @@
|
||||
package com.pitchedapps.frost.utils
|
||||
|
||||
import android.content.Context
|
||||
import android.text.TextUtils
|
||||
import ca.allanwang.kau.utils.use
|
||||
import okhttp3.HttpUrl
|
||||
import org.jetbrains.anko.doAsync
|
||||
|
||||
/**
|
||||
* Created by Allan Wang on 2017-09-24.
|
||||
*/
|
||||
object FrostAdBlock : AdBlocker("adblock.txt")
|
||||
object FrostPglAdBlock : AdBlocker("pgl.yoyo.org.txt")
|
||||
|
||||
/**
|
||||
* Base implementation of an AdBlocker
|
||||
* Wrap this in a singleton and initialize it to use it
|
||||
*/
|
||||
open class AdBlocker(val assetPath: String) {
|
||||
|
||||
val data: MutableSet<String> = mutableSetOf()
|
||||
|
||||
fun init(context: Context) {
|
||||
doAsync {
|
||||
data.addAll(context.assets.open(assetPath).bufferedReader().use { it.readLines().filter { !it.startsWith("#") } })
|
||||
L.i("Initialized adblock for $assetPath with ${data.size} hosts")
|
||||
}
|
||||
}
|
||||
|
||||
fun isAd(url: String?): Boolean {
|
||||
val httpUrl = HttpUrl.parse(url) ?: return false
|
||||
return isAdHost(httpUrl.host())
|
||||
}
|
||||
|
||||
tailrec fun isAdHost(host: String): Boolean {
|
||||
if (TextUtils.isEmpty(host))
|
||||
return false
|
||||
val index = host.indexOf(".")
|
||||
if (index < 0 || index + 1 < host.length) return false
|
||||
if (host.contains(host)) return true
|
||||
return isAdHost(host.substring(index + 1))
|
||||
}
|
||||
}
|
@ -3,11 +3,8 @@ package com.pitchedapps.frost.web
|
||||
import android.webkit.WebResourceRequest
|
||||
import android.webkit.WebResourceResponse
|
||||
import android.webkit.WebView
|
||||
import ca.allanwang.kau.kotlin.LazyContext
|
||||
import ca.allanwang.kau.kotlin.lazyContext
|
||||
import ca.allanwang.kau.utils.use
|
||||
import com.pitchedapps.frost.utils.FrostPglAdBlock
|
||||
import com.pitchedapps.frost.utils.L
|
||||
import com.pitchedapps.frost.utils.Prefs
|
||||
import okhttp3.HttpUrl
|
||||
import java.io.ByteArrayInputStream
|
||||
|
||||
@ -23,7 +20,7 @@ private val blankResource: WebResourceResponse by lazy { WebResourceResponse("te
|
||||
//these hosts will redirect to a blank resource
|
||||
private val blacklistHost: Set<String> =
|
||||
setOf(
|
||||
// "edge-chat.facebook.com" //todo make more specific? This is required for message responses
|
||||
// "edge-chat.facebook.com" //todo make more specific? This is required for message responses
|
||||
)
|
||||
|
||||
//these hosts will return null and skip logging
|
||||
@ -41,17 +38,13 @@ private val adWhitelistHost: Set<String> =
|
||||
"scontent-sea1-1.xx.fbcdn.net"
|
||||
)
|
||||
|
||||
private val adblock: LazyContext<Set<String>> = lazyContext {
|
||||
it.assets.open("adblock.txt").bufferedReader().use { it.readLines().toSet() }
|
||||
}
|
||||
|
||||
fun WebView.shouldFrostInterceptRequest(request: WebResourceRequest): WebResourceResponse? {
|
||||
val httpUrl = HttpUrl.parse(request.url?.toString() ?: return null) ?: return null
|
||||
val host = httpUrl.host()
|
||||
val url = httpUrl.toString()
|
||||
if (blacklistHost.contains(host)) return blankResource
|
||||
// if (blacklistHost.contains(host)) return blankResource
|
||||
if (whitelistHost.contains(host)) return null
|
||||
if (!adWhitelistHost.contains(host) && adblock(context).any { url.contains(it) }) return blankResource
|
||||
if (!adWhitelistHost.contains(host) && FrostPglAdBlock.isAdHost(host)) return blankResource
|
||||
// if (!shouldLoadImages && !Prefs.loadMediaOnMeteredNetwork && request.isMedia) return blankResource
|
||||
L.v("Intercept Request", "$host $url")
|
||||
return null
|
||||
|
@ -2,6 +2,7 @@
|
||||
<resources>
|
||||
|
||||
<string name="notification_frequency">Notification Frequency</string>
|
||||
<string name="no_notifications">No Notifications</string>
|
||||
<string name="notification_keywords">Keywords</string>
|
||||
<string name="notification_keywords_desc">Does not notify when notification contains any of these keys.</string>
|
||||
<string name="add_keyword">Add Keyword</string>
|
||||
|
@ -11,7 +11,7 @@
|
||||
<item text="Set background back to white on non facebook pages" />
|
||||
<item text="Make read notification/message colors more obvious" />
|
||||
<item text="Clean up and small bug fixes" />
|
||||
<item text="" />
|
||||
<item text="Fix facebook link parsing issue for many links" />
|
||||
<item text="" />
|
||||
<item text="" />
|
||||
|
||||
|
@ -16,7 +16,12 @@
|
||||
This is also why I don't require the wakelock permission]]></answer>
|
||||
|
||||
<question><![CDATA[Can I disable auto play for videos?]]></question>
|
||||
<answer><![CDATA[Facebook already has a toggle. <br/> Go to menu → account settings → videos <br/> and change it from there.]]></answer>
|
||||
<answer>
|
||||
<![CDATA[Facebook already has a toggle. <br/> Go to menu → account settings → videos <br/> and change it from there.]]></answer>
|
||||
|
||||
<question><![CDATA[The overlay is not loading!]]></question>
|
||||
<answer><![CDATA[This usually happens if you try sharing something to Facebook from your browser, which is logged into a different account.
|
||||
In this case, make sure you switch Frost to the right account first, as we cannot auto detect it.]]></answer>
|
||||
|
||||
<!--
|
||||
<question><![CDATA[]]></question>
|
||||
|
@ -5,6 +5,7 @@
|
||||
* Set background back to white on non facebook pages
|
||||
* Make read notification/message colors more obvious
|
||||
* Clean up and small bug fixes
|
||||
* Fix facebook link parsing issue for many links
|
||||
|
||||
## v1.5.2
|
||||
* Add default download manager to download all files
|
||||
|
@ -17,7 +17,7 @@ MIN_SDK=21
|
||||
TARGET_SDK=26
|
||||
BUILD_TOOLS=26.0.1
|
||||
|
||||
KAU=6411200
|
||||
KAU=3.4.3
|
||||
KOTLIN=1.1.4-3
|
||||
|
||||
COMMONS_TEXT=1.1
|
||||
|
Loading…
Reference in New Issue
Block a user