Skip to content

Commit

Permalink
Add an Ad/Tracking blocker. Allow Disable/Enable Blocker. Improve con…
Browse files Browse the repository at this point in the history
…sole interface
  • Loading branch information
StringManolo committed Jul 17, 2024
1 parent 4e7943e commit 9cf38cc
Show file tree
Hide file tree
Showing 23 changed files with 610 additions and 1 deletion.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified Panther/app/build/dexedClasses/classes.dex
Binary file not shown.
Binary file modified Panther/app/build/output/app-debug.apk
Binary file not shown.
Binary file modified Panther/app/build/output/app-unsigned-debug.apk
Binary file not shown.
Binary file modified Panther/app/build/resources.ap_
Binary file not shown.
523 changes: 523 additions & 0 deletions Panther/app/src/main/assets/adservers.txt

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,16 @@
import android.webkit.DownloadListener;
import android.webkit.URLUtil;
import android.webkit.PermissionRequest;
import android.webkit.WebResourceRequest;
import android.webkit.WebResourceResponse;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class MainActivity extends Activity {
Intent intentArchivos = null;
Expand Down Expand Up @@ -70,6 +80,7 @@ public class MainActivity extends Activity {
String SSE = "https://html.duckduckgo.com/html/?q=";
int progress = 0;
boolean jsEnabled = true;
boolean blockerEnabled = true;

@Override
public void onCreate(Bundle savedInstanceState) {
Expand Down Expand Up @@ -136,6 +147,16 @@ public void onItemClick(AdapterView < ? > adapterView, View view, int position,
}
Panther.getSettings().setJavaScriptEnabled(jsEnabled);
}

if (value.equals("Blocker")) {
if (blockerEnabled) {
blockerEnabled = false;
Toast.makeText(getApplicationContext(), "Blocker is now disabled", Toast.LENGTH_SHORT).show();
} else {
blockerEnabled = true;
Toast.makeText(getApplicationContext(), "Blocker is now removing ads and trackers", Toast.LENGTH_SHORT).show();
}
}

if (value.equals("Exit")) {
Panther.clearCache(true);
Expand All @@ -161,8 +182,12 @@ public void onItemClick(AdapterView < ? > adapterView, View view, int position,
}
});

/* Hidden by default */
listView.setVisibility(View.INVISIBLE);
textView.setVisibility(View.INVISIBLE);
consoleOutput.setVisibility(View.INVISIBLE);
consoleInput.setVisibility(View.INVISIBLE);
executeButton.setVisibility(View.INVISIBLE);

if (Build.VERSION.SDK_INT < 18) {
/* Panther.getSettings().setRenderPriority(RenderPriority.HIGH); */
Expand All @@ -185,7 +210,64 @@ public void onItemClick(AdapterView < ? > adapterView, View view, int position,
Panther.getSettings().setBuiltInZoomControls(true);



Panther.setWebViewClient(new WebViewClient() {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
String url = request.getUrl().toString();

// Leer las URLs de adservers.txt en assets
List<String> adServers = loadAdServersFromAssets(view.getContext());

// Verificar si la URL solicitada coincide con alguna URL de adservers.txt
if (blockerEnabled != false && adServers != null && adServers.size() > 0) {
for (String adServerUrl : adServers) {
if (url.contains(adServerUrl)) {
String adBlockerCode = ""
+ "<!doctype html><html><head><meta charset='utf-8'></head>"
+ "<body><h1>Panther AD Blocker</h1>"
+ "Blocked '" + adServerUrl + "' AD Server."
+ "</body></html>";
InputStream adBlockerPage = new ByteArrayInputStream(adBlockerCode.getBytes(StandardCharsets.UTF_8));
return new WebResourceResponse("text/html", "utf-8", adBlockerPage);
}
}
}

// Permitir todas las demás solicitudes
return super.shouldInterceptRequest(view, request);
}

private List<String> loadAdServersFromAssets(Context context) {
List<String> adServers = new ArrayList<>();
BufferedReader reader = null;
try {
// Abrir el archivo adservers.txt en assets
InputStream is = context.getAssets().open("adservers.txt");
reader = new BufferedReader(new InputStreamReader(is));
String line;
while ((line = reader.readLine()) != null) {
// Agregar cada línea (que representa una URL de servidor de anuncios) a la lista
adServers.add(line.trim()); // trim() para eliminar espacios en blanco al inicio y final
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return adServers;
}





@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
Expand Down
1 change: 0 additions & 1 deletion Panther/app/src/main/res/drawable/consoleborder.xml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
<!-- res/drawable/edittext_border.xml -->
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#df000000" />
<corners android:radius="3dp" />
Expand Down
1 change: 1 addition & 0 deletions Panther/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<string name="title_activity_main">MAIN_ACTIVITY</string>

<string-array name="array_technology">
<item>Blocker</item>
<item>Console</item>
<item>Javascript</item>
<item>Search Engine</item>
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Panther is a privacy-focused Android browser based on WebView.


### Features
- Blocker
- Blocks common AD servers by replacing the downloaded AD by a custom file
- Blocks common Trackers by replacing the downloaded javascript by a custom file
<br>

- Console support
- Add a console to view the console.log in Android, run commands, etc
Expand Down

0 comments on commit 9cf38cc

Please sign in to comment.