增加GIF屏蔽;在Activity中处理屏蔽规则
This commit is contained in:
285
main/java/com/hty/browser/ADBlockActivity.java
Normal file
285
main/java/com/hty/browser/ADBlockActivity.java
Normal file
@@ -0,0 +1,285 @@
|
||||
package com.hty.browser;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.ContentValues;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.graphics.Color;
|
||||
import android.media.MediaScannerConnection;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.util.Log;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.WindowManager;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ListView;
|
||||
import android.widget.RadioButton;
|
||||
import android.widget.Spinner;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.FileWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
public class ADBlockActivity extends Activity {
|
||||
EditText editText;
|
||||
ImageButton imageButton_clear;
|
||||
ListView listView;
|
||||
ArrayAdapter<String> adapter;
|
||||
List<String> datas0, datas;
|
||||
//String[] SL;
|
||||
InputMethodManager IMM;
|
||||
int position;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_adblock);
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
IMM = (InputMethodManager) getApplicationContext().getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
|
||||
editText = (EditText) findViewById(R.id.editText);
|
||||
editText.addTextChangedListener(new TextWatcher(){
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence s, int start, int count,int after) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence s, int start, int before, int count) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable s) {
|
||||
if (s.toString().equals("")) {
|
||||
imageButton_clear.setVisibility(View.GONE);
|
||||
} else {
|
||||
imageButton_clear.setVisibility(View.VISIBLE);
|
||||
}
|
||||
search();
|
||||
}
|
||||
});
|
||||
|
||||
imageButton_clear = (ImageButton) findViewById(R.id.imageButton_clear);
|
||||
imageButton_clear.setOnClickListener(new View.OnClickListener(){
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
editText.setText("");
|
||||
}
|
||||
});
|
||||
imageButton_clear.setVisibility(View.GONE);
|
||||
|
||||
datas0 = new ArrayList<>();
|
||||
datas = new ArrayList<>();
|
||||
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1, datas);
|
||||
listView = (ListView) findViewById(R.id.listView);
|
||||
listView.setAdapter(adapter);
|
||||
listView.setOnCreateContextMenuListener(new View.OnCreateContextMenuListener() {
|
||||
@Override
|
||||
public void onCreateContextMenu(ContextMenu menu, View view, ContextMenu.ContextMenuInfo menuInfo) {
|
||||
AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
String title = ((TextView) info.targetView.findViewById(android.R.id.text1)).getText().toString();
|
||||
menu.setHeaderTitle(title);
|
||||
menu.setHeaderIcon(R.drawable.link);
|
||||
String[] sm = { "打开", "复制", "分享", "修改", "删除" };
|
||||
for (int i=0; i<sm.length; i++) {
|
||||
menu.add(0, i, i, sm[i]);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//SL = readFile("blockrules").split(",");
|
||||
datas0 = Arrays.asList(readFile("blockrules").split(","));
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "Read: " + datas0.toString());
|
||||
search();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
String[] sm = { "重载", "保存", "退出" };
|
||||
for (int i=0; i<sm.length; i++) {
|
||||
menu.add(0, i, i, sm[i]);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
switch (id) {
|
||||
case 0:
|
||||
//SL = readFile("blockrules").split(",");
|
||||
datas0 = Arrays.asList(readFile("blockrules").split(","));
|
||||
search();
|
||||
break;
|
||||
case 1:
|
||||
String s = datas.toString().replace("[", "").replace("]", "");
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "Write: " + s);
|
||||
writeFile("blockrules", s);
|
||||
break;
|
||||
case 2:
|
||||
finish();
|
||||
break;
|
||||
case android.R.id.home:
|
||||
finish();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
AdapterView.AdapterContextMenuInfo menuInfo = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
|
||||
int index = menuInfo.position;
|
||||
position = listView.getFirstVisiblePosition();
|
||||
String url = ((TextView) menuInfo.targetView.findViewById(android.R.id.text1)).getText().toString();
|
||||
switch (item.getItemId()) {
|
||||
case 0:
|
||||
Intent intent = new Intent(ADBlockActivity.this, MainActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
intent.putExtra("newWindow", true);
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
break;
|
||||
case 1:
|
||||
ClipboardManager CM = (ClipboardManager) getSystemService(CLIPBOARD_SERVICE);
|
||||
CM.setPrimaryClip(ClipData.newPlainText("link", url));
|
||||
Toast.makeText(getApplicationContext(), "已复制", Toast.LENGTH_SHORT).show();
|
||||
break;
|
||||
case 2:
|
||||
intent = new Intent();
|
||||
intent.setAction(Intent.ACTION_SEND);
|
||||
intent.putExtra(Intent.EXTRA_TEXT, url);
|
||||
intent.setType("text/plain");
|
||||
startActivity(Intent.createChooser(intent, "分享"));
|
||||
break;
|
||||
case 3:
|
||||
final EditText editText_url = new EditText(ADBlockActivity.this);
|
||||
editText_url.setMaxLines(3);
|
||||
editText_url.setHint("网址");
|
||||
editText_url.setText(url);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(ADBlockActivity.this);
|
||||
builder.setIcon(android.R.drawable.btn_star_big_on);
|
||||
builder.setTitle("修改");
|
||||
builder.setView(editText_url);
|
||||
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String surl = editText_url.getText().toString();
|
||||
Field field = null;
|
||||
try {
|
||||
//通过反射获取dialog中的私有属性mShowing
|
||||
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
|
||||
field.setAccessible(true);//设置该属性可以访问
|
||||
} catch (Exception e) {
|
||||
}
|
||||
if (surl.startsWith("http://") || surl.startsWith("https://") && !url.equals(surl)) {
|
||||
datas.set(index, surl);
|
||||
adapter.notifyDataSetChanged();
|
||||
} else {
|
||||
editText_url.setError("网址错误!");
|
||||
try {
|
||||
//设置dialog不可关闭
|
||||
field.set(dialog, false);
|
||||
dialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
IMM.hideSoftInputFromWindow(editText_url.getWindowToken(), 0);
|
||||
Field field = null;
|
||||
try {
|
||||
//通过反射获取dialog中的私有属性mShowing
|
||||
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
|
||||
field.setAccessible(true);//设置该属性可以访问
|
||||
} catch (Exception e) {
|
||||
}
|
||||
try {
|
||||
field.set(dialog, true);
|
||||
dialog.dismiss();
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
});
|
||||
builder.create().show();
|
||||
break;
|
||||
case 4:
|
||||
position = listView.getFirstVisiblePosition();
|
||||
datas.remove(url);
|
||||
adapter.notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void search() {
|
||||
datas.clear();
|
||||
String s = editText.getText().toString();
|
||||
for (int i=0; i<datas0.size(); i++) {
|
||||
if (s.equals("") || datas0.get(i).contains(s))
|
||||
datas.add(datas0.get(i));
|
||||
}
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
String readFile(String filename) {
|
||||
String s = "";
|
||||
FileInputStream FIS;
|
||||
try {
|
||||
FIS = openFileInput(filename);
|
||||
byte[] buffer = new byte[1024];
|
||||
ByteArrayOutputStream BAOS = new ByteArrayOutputStream();
|
||||
int len;
|
||||
while ((len = FIS.read(buffer)) != -1) {
|
||||
BAOS.write(buffer, 0, len);
|
||||
}
|
||||
s = BAOS.toString();
|
||||
FIS.close();
|
||||
BAOS.close();
|
||||
return s;
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
void writeFile(String filename, String s) {
|
||||
FileOutputStream outStream = null;
|
||||
try {
|
||||
outStream = openFileOutput("blockrules", Context.MODE_PRIVATE);
|
||||
outStream.write(s.getBytes());
|
||||
outStream.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -43,7 +43,6 @@ import android.content.res.Configuration;
|
||||
import android.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.Color;
|
||||
import android.graphics.Matrix;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.media.MediaScannerConnection;
|
||||
@@ -150,6 +149,14 @@ public class MainActivity extends Activity {
|
||||
dir.mkdirs();
|
||||
}
|
||||
|
||||
String path1 = getFilesDir().getAbsolutePath() + "/blockrules";
|
||||
File file = new File(path1);
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
|
||||
|
||||
@@ -673,7 +680,7 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
private void MenuDialog() {
|
||||
String[] items = { "新建窗口", "关闭当前窗口", "收藏当前页", "收藏夹", "查找", "分享", "网页信息", "视频独立播放", "视频截图", "视频在播放器中打开", "资源探查", "查看源码", "保存", "全屏", "广告过滤规则", "清除当前页面缓存", "设置", "检查更新", "关于", "退出", "ExpandableListView" };
|
||||
String[] items = { "新建窗口", "关闭当前窗口", "收藏当前页", "收藏夹", "查找", "分享", "网页信息", "视频独立播放", "视频截图", "视频在播放器中打开", "资源探查", "查看源码", "保存", "全屏", "广告屏蔽", "清除当前页面缓存", "设置", "检查更新", "关于", "退出", "ExpandableListView" };
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setTitle("菜单");
|
||||
//builder.setIcon(android.R.drawable.ic_menu_preferences);
|
||||
@@ -689,7 +696,7 @@ public class MainActivity extends Activity {
|
||||
case 1:
|
||||
list_webView.remove(currentPage);
|
||||
if (list_webView.size() == 0) {
|
||||
newWindow(sharedPreferences.getString("homepage","http://www.baidu.com"));
|
||||
newWindow(sharedPreferences.getString("homepage", "http://www.baidu.com"));
|
||||
} else {
|
||||
if (currentPage == list_webView.size())
|
||||
currentPage--;
|
||||
@@ -716,7 +723,7 @@ public class MainActivity extends Activity {
|
||||
editText_url.setText(list_webView.get(currentPage).getUrl());
|
||||
layout.addView(editText_url);
|
||||
final Spinner spinner = new Spinner(MainActivity.this);
|
||||
spinner.setBackgroundColor(Color.GRAY);
|
||||
//spinner.setBackgroundColor(Color.GRAY);
|
||||
ArrayList<String> list = new ArrayList<>();
|
||||
DBHelper helper = new DBHelper(MainActivity.this);
|
||||
Cursor cursor = helper.category();
|
||||
@@ -940,7 +947,7 @@ public class MainActivity extends Activity {
|
||||
isFullScreen = true;
|
||||
break;
|
||||
case 14:
|
||||
DialogBlockList();
|
||||
startActivityForResult(new Intent(MainActivity.this, ADBlockActivity.class), 0);
|
||||
break;
|
||||
case 15:
|
||||
list_webView.get(currentPage).clearCache(true);
|
||||
@@ -970,19 +977,19 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
|
||||
void DialogBlock(String content){
|
||||
final EditText ETrule = new EditText(this);
|
||||
ETrule.setText(content);
|
||||
final AlertDialog dialogRule = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setTitle("屏蔽规则").setView(ETrule).setCancelable(false).setPositiveButton("添加",null).setNeutralButton("删除",null).setNegativeButton("取消",null).create();
|
||||
dialogRule.show();
|
||||
dialogRule.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
final EditText edit_rule = new EditText(this);
|
||||
edit_rule.setText(content);
|
||||
final AlertDialog dialog = new AlertDialog.Builder(this).setIcon(R.drawable.ic_launcher).setTitle("屏蔽规则").setView(edit_rule).setCancelable(false).setPositiveButton("添加",null).setNegativeButton("取消",null).create();
|
||||
dialog.show();
|
||||
dialog.getButton(AlertDialog.BUTTON_POSITIVE)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
boolean exist = false;
|
||||
String rule = ETrule.getText().toString();
|
||||
List<String> rulelist = new ArrayList<String>(Arrays.asList(ReadFile("blockrules").split("\n")));
|
||||
for(int i=0;i<rulelist.size();i++){
|
||||
if(rulelist.get(i).equals(rule)){
|
||||
String rule = edit_rule.getText().toString();
|
||||
List<String> list_rule = new ArrayList<>(Arrays.asList(readFile("blockrules").split(",")));
|
||||
for (int i=0; i<list_rule.size(); i++) {
|
||||
if (list_rule.get(i).equals(rule)) {
|
||||
Toast.makeText(MainActivity.this, "此条规则已经存在!", Toast.LENGTH_SHORT).show();
|
||||
exist = true;
|
||||
break;
|
||||
@@ -990,55 +997,26 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
if (!exist) {
|
||||
addRule(rule);
|
||||
dialogRule.dismiss();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
dialogRule.getButton(AlertDialog.BUTTON_NEUTRAL)
|
||||
dialog.getButton(AlertDialog.BUTTON_NEGATIVE)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
String rule = ETrule.getText().toString();
|
||||
List<String> rulelist = new ArrayList<String>(Arrays.asList(ReadFile("blockrules").split("\n")));
|
||||
for(int i=0;i<rulelist.size();i++){
|
||||
if(rulelist.get(i).equals(rule)){
|
||||
rulelist.remove(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
String content="";
|
||||
for (int i=0; i<rulelist.size(); i++) {
|
||||
content += rulelist.get(i) + "\n";
|
||||
}
|
||||
FileOutputStream outStream = null;
|
||||
try {
|
||||
outStream = MainActivity.this.openFileOutput("blockrules", Context.MODE_PRIVATE);
|
||||
outStream.write((content).getBytes());
|
||||
outStream.close();
|
||||
} catch (Exception e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", e.toString());
|
||||
}
|
||||
dialogRule.dismiss();
|
||||
ADBlock();
|
||||
}
|
||||
}
|
||||
);
|
||||
dialogRule.getButton(AlertDialog.BUTTON_NEGATIVE)
|
||||
.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
dialogRule.dismiss();
|
||||
dialog.dismiss();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
void addRule(String content){
|
||||
void addRule(String content) {
|
||||
FileOutputStream outStream = null;
|
||||
try {
|
||||
outStream = openFileOutput("blockrules", Context.MODE_APPEND);
|
||||
outStream.write((content+"\n").getBytes());
|
||||
outStream.write(("," + content).getBytes());
|
||||
outStream.close();
|
||||
ADBlock();
|
||||
} catch (Exception e) {
|
||||
@@ -1046,102 +1024,44 @@ public class MainActivity extends Activity {
|
||||
}
|
||||
}
|
||||
|
||||
void DialogBlockList(){
|
||||
final String[] datas = ReadFile("blockrules").split("\n");
|
||||
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, datas);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this);
|
||||
builder.setIcon(R.drawable.ic_launcher);
|
||||
builder.setTitle("屏蔽规则列表:");
|
||||
builder.setAdapter(adapter, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
DialogBlock(datas[which]);
|
||||
//Toast.makeText(MainActivity.this, "你点击了第" + which + "个item", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
});
|
||||
builder.setPositiveButton("确定", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
builder.setNeutralButton("清空", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
AlertDialog.Builder builder1 = new AlertDialog.Builder(MainActivity.this);
|
||||
builder1.setMessage("操作不可逆,确认清空吗?");
|
||||
builder1.setIcon(R.drawable.ic_launcher);
|
||||
builder1.setTitle("警告");
|
||||
builder1.setPositiveButton("确认", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
String filepath = getFilesDir().getAbsolutePath() + "/blockrules";
|
||||
File file = new File(filepath);
|
||||
//if(file.isFile() && file.exists()) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", String.valueOf(file.delete()));
|
||||
//}
|
||||
}
|
||||
});
|
||||
builder1.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
builder1.create().show();
|
||||
}
|
||||
});
|
||||
builder.setNegativeButton("取消", new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
|
||||
}
|
||||
});
|
||||
builder.show();
|
||||
}
|
||||
|
||||
String ReadFile(String filename) {
|
||||
String readFile(String filename) {
|
||||
String s = "";
|
||||
FileInputStream istream;
|
||||
try {
|
||||
istream = MainActivity.this.openFileInput(filename);
|
||||
istream = openFileInput(filename);
|
||||
byte[] buffer = new byte[1024];
|
||||
ByteArrayOutputStream ostream = new ByteArrayOutputStream();
|
||||
int len;
|
||||
while ((len = istream.read(buffer)) != -1) {
|
||||
ostream.write(buffer, 0, len);
|
||||
}
|
||||
s = new String(ostream.toByteArray());
|
||||
s = ostream.toString();
|
||||
istream.close();
|
||||
ostream.close();
|
||||
return s;
|
||||
} catch (FileNotFoundException e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
String path = getFilesDir().getAbsolutePath() + "/blockrules";
|
||||
File file = new File(path);
|
||||
try {
|
||||
file.createNewFile();
|
||||
} catch (IOException e1) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e1);
|
||||
}
|
||||
return s;
|
||||
} catch (IOException e) {
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + e);
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
void ADBlock(){
|
||||
String s = ReadFile("blockrules");
|
||||
void ADBlock() {
|
||||
String s = readFile("blockrules");
|
||||
//Log.e(Thread.currentThread().getStackTrace()[2] + "", "" + s);
|
||||
if(!"".equals(s)) {
|
||||
String rules = s.replace("\n", ",");
|
||||
if (rules.endsWith(",")) {
|
||||
rules = rules.substring(0, rules.length() - 1);
|
||||
}
|
||||
String js = "javascript:var rules='" + rules + "';var rule=new Array();rule=rules.split(',');var img=document.getElementsByTagName('img');for(i=0;i<img.length;i++){for(j=0;j<rule.length;j++){if(img[i].src.indexOf(rule[j])!=-1){img[i].style.display='none';}}}";
|
||||
if(!s.equals("")) {
|
||||
// if (s.endsWith(",")) {
|
||||
// s = s.substring(0, s.length() - 1);
|
||||
// }
|
||||
String js = "javascript:var rules='" + s + "';var rule=new Array();rule=rules.split(',');var img=document.getElementsByTagName('img');for(i=0;i<img.length;i++){for(j=0;j<rule.length;j++){if(img[i].src.indexOf(rule[j])!=-1){img[i].style.display='none';}}}";
|
||||
list_webView.get(currentPage).loadUrl(js);
|
||||
}
|
||||
}
|
||||
|
||||
void GIFBlock() {
|
||||
String js = "javascript:var img=document.getElementsByTagName('img');for(i=0;i<img.length;i++){if(img[i].src.indexOf('.gif')!=-1){img[i].style.display='none';}}";
|
||||
list_webView.get(currentPage).loadUrl(js);
|
||||
}
|
||||
|
||||
void iframeBlock() {
|
||||
String js = "javascript:var iframes=document.getElementsByTagName('iframe');for(i=0;i<iframes.length;i++){iframes[i].style.display='none';}document.getElementById('win-pop-foot').style.display='none';document.getElementById('win-pop-foot1').style.display='none';";
|
||||
list_webView.get(currentPage).loadUrl(js);
|
||||
@@ -1414,6 +1334,9 @@ public class MainActivity extends Activity {
|
||||
if (sharedPreferences.getBoolean("switch_adBlock", false)) {
|
||||
ADBlock();
|
||||
}
|
||||
if (sharedPreferences.getBoolean("switch_gifBlock", false)) {
|
||||
GIFBlock();
|
||||
}
|
||||
if (sharedPreferences.getBoolean("switch_iframeBlock", false)) {
|
||||
if (view.getUrl() != null) {
|
||||
if (!view.getUrl().contains("baidu.com")) {
|
||||
|
||||
Reference in New Issue
Block a user