link of keywords hide and highlight can be set

This commit is contained in:
sonichy 2019-02-16 00:30:37 +08:00
parent 278e169477
commit 4d6588f728
7 changed files with 86 additions and 46 deletions

BIN
app.apk

Binary file not shown.

View File

@ -2,7 +2,7 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.hty.browser"
android:versionCode="3"
android:versionName="3.10">
android:versionName="3.11">
<uses-sdk
android:minSdkVersion="16"

View File

@ -9,17 +9,17 @@ p { text-indent:2em; }
</style>
</head>
<body>
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V3.10</h2>
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V3.11</h2>
<p>内置扩展的浏览器。</p>
<p>扩展:[国产]高亮,广告图片自定义过滤</p>
<p>扩展:链接关键字过滤,链接关键字高亮,图片自定义过滤,视频独立播放</p>
<p>作者:黄颖</p>
<p>主页<a href="https://github.com/sonichy" target="_blank">https://github.com/sonichy</a></p>
<p>源码<a href="https://github.com/sonichy/Android_HTYBrowser" target="_blank">https://github.com/sonichy/Android_HTYBrowser</a></p>
<p>E-mailsonichy@163.com</p>
<p>QQ84429027</p>
<h3>参考:</h3>
<p><a href="https://www.jianshu.com/p/6e38e1ef203a" target="_blank">Android WebView 三种文件下载方式</a></p>
<p><a href="https://blog.csdn.net/lowprofile_coding/article/details/77852131" target="_blank">自动安装apk包</a></p>
<h3>更新日志:</h3>
<h3>V3.11 (2019-02-13)</h3><ol><li>链接中的关键字屏蔽、高亮可设置。</li></ol>
<h3>V3.10 (2019-02-10)</h3><ol><li>增加:收藏前修改,收藏后修改,修改校验。</li></ol>
<h3>V3.9 (2018-12-20)</h3><ol><li>视频独立播放JS读不到iframe里的video使用跳转iframe代替。</li></ol>
<h3>V3.8 (2018-07-14)</h3><ol><li>增加定位权限。</li></ol>

View File

@ -226,10 +226,6 @@ public class MainActivity extends Activity {
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pgb1.setVisibility(View.INVISIBLE);
String js = "";
// 链接关键字链接高亮屏蔽
js = "javascript:var a=document.getElementsByTagName('a');for(var i=0;i<a.length;i++){if(a[i].textContent.indexOf('国产')!=-1){a[i].style.color='white';a[i].style.backgroundColor='#DA3434';}if(a[i].textContent.indexOf('习近平')!=-1 || a[i].textContent.indexOf('总书记')!=-1){a[i].textContent='';}}";
view.loadUrl(js);
}
@Override
@ -280,24 +276,30 @@ public class MainActivity extends Activity {
public void onProgressChanged(WebView view, int newProgress) {
super.onProgressChanged(view, newProgress);
pgb1.setProgress(newProgress);
/*
if(!isFullScreen) {
if (newProgress == 100) {
pgb1.setVisibility(View.INVISIBLE);
} else {
pgb1.setVisibility(View.VISIBLE);
}
}
*/
if(sharedPreferences.getBoolean("switch_adBlock",true)){
ADBlock();
}
if(sharedPreferences.getBoolean("switch_iframeBlock",false)) {
//Log.e("line292", "progress:" + newProgress);
if (!view.getUrl().contains("baidu.com")){
iframeBlock();
}
}
// 链接关键字屏蔽
if(sharedPreferences.getBoolean("switch_filter",false)){
String sf = sharedPreferences.getString("filter","");
if(!sf.equals("")) {
String js = "javascript:var s='"+sf+"';var sl=s.split(';');var a=document.getElementsByTagName('a');for(var i=0;i<a.length;i++){for(var j=0;j<sl.length;j++){if(a[i].textContent.indexOf(sl[j])!=-1){a[i].textContent='';}}}";
view.loadUrl(js);
}
}
// 链接关键字高亮
if(sharedPreferences.getBoolean("switch_highlight",false)){
String shl = sharedPreferences.getString("highlight","");
if(!shl.equals("")) {
String js = "javascript:var s='"+shl+"';var sl=s.split(';');var a=document.getElementsByTagName('a');for(var i=0;i<a.length;i++){for(var j=0;j<sl.length;j++){if(a[i].textContent.indexOf(sl[j])!=-1){a[i].style.color='white';a[i].style.backgroundColor='#DA3434';}}}";
view.loadUrl(js);
}
}
}
// 获取网页标题
@ -534,10 +536,9 @@ public class MainActivity extends Activity {
private class MyWebViewDownLoadListener implements DownloadListener {
@Override
public void onDownloadStart(String url, String userAgent, String contentDisposition, String mimetype, long contentLength) {
// Uri uri = Uri.parse(url);
// Intent intent = new Intent(Intent.ACTION_VIEW, uri);
// startActivity(intent);
downloadBySystem(url,"","");
Log.e("Download", url);
//if(!url.contains("baidu.com"))
downloadBySystem(url, "", "");
}
}
@ -727,7 +728,6 @@ public class MainActivity extends Activity {
@Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
// if (this.getResources().getConfiguration().orientation ==
// Configuration.ORIENTATION_LANDSCAPE) {
@ -813,7 +813,6 @@ public class MainActivity extends Activity {
helper.insert(values);
} else {
Toast.makeText(getApplicationContext(), "网址已存在", Toast.LENGTH_SHORT).show();
IMM.hideSoftInputFromWindow(ET_title.getWindowToken(), 0);
}
try {
//关闭
@ -821,6 +820,7 @@ public class MainActivity extends Activity {
dialog.dismiss();
} catch (Exception ex) {
}
IMM.hideSoftInputFromWindow(ET_title.getWindowToken(), 0);
} else {
if (stitle.equals("")){
ET_title.setError("标题不能为空!");

View File

@ -8,30 +8,38 @@ import android.preference.PreferenceActivity;
public class SettingsActivity extends PreferenceActivity implements OnSharedPreferenceChangeListener{
private EditTextPreference ETP_homepage;
SharedPreferences sharedPreferences;
private EditTextPreference ETP_homepage, ETP_filter, ETP_highlight;
SharedPreferences SP;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
addPreferencesFromResource(R.xml.preference);
ETP_homepage = (EditTextPreference) findPreference("homepage");
sharedPreferences = getPreferenceScreen().getSharedPreferences();
sharedPreferences.registerOnSharedPreferenceChangeListener(this);
ETP_filter = (EditTextPreference) findPreference("filter");
ETP_highlight = (EditTextPreference) findPreference("highlight");
SP = getPreferenceScreen().getSharedPreferences();
SP.registerOnSharedPreferenceChangeListener(this);
}
@Override
// Activity启动时修改列表项目值
// 启动时显示
protected void onResume() {
super.onResume();
ETP_homepage.setSummary(sharedPreferences.getString("homepage","http://www.baidu.com"));
ETP_homepage.setSummary(SP.getString("homepage","http://www.baidu.com"));
ETP_filter.setSummary(SP.getString("filter",""));
ETP_highlight.setSummary(SP.getString("highlight",""));
}
@Override
// 编辑后确定修改列表项目值
// 修改后显示
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) {
if(key.equals("homepage")){
ETP_homepage.setSummary(sharedPreferences.getString(key,""));
}else if(key.equals("filter")){
ETP_filter.setSummary(sharedPreferences.getString(key,""));
}else if(key.equals("highlight")){
ETP_highlight.setSummary(sharedPreferences.getString(key,""));
}
}
}

View File

@ -1,21 +1,53 @@
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android"
android:title="设置">
<EditTextPreference
android:key="homepage"
android:defaultValue="http://www.baidu.com"
android:summary="http://www.baidu.com"
android:title="主页"
android:background="#282828"/>
<EditTextPreference
android:key="homepage"
android:defaultValue="http://www.baidu.com"
android:summary="http://www.baidu.com"
android:title="主页"
android:textColor="@android:color/holo_blue_dark"/>
<SwitchPreference
android:key="switch_adBlock"
android:defaultValue="true"
android:title="广告过滤"/>
<SwitchPreference
android:key="switch_iframeBlock"
android:defaultValue="false"
android:title="iframe过滤"/>
<PreferenceCategory
android:title="关键字过滤">
<SwitchPreference
android:key="switch_adBlock"
android:defaultValue="true"
android:title="广告过滤"/>
<SwitchPreference
android:key="switch_iframeBlock"
android:key="switch_filter"
android:defaultValue="false"
android:title="iframe过滤"/>
android:title="过滤开关"/>
<EditTextPreference
android:key="filter"
android:title="过滤文本"
android:summary="关键字之间用;间隔"
android:textColor="@android:color/holo_blue_dark"/>
</PreferenceCategory>
<PreferenceCategory
android:title="关键字高亮">
<SwitchPreference
android:key="switch_highlight"
android:defaultValue="false"
android:title="高亮开关"/>
<EditTextPreference
android:key="highlight"
android:title="高亮文本"
android:summary="关键字之间用;间隔"
android:textColor="@android:color/holo_blue_dark"/>
</PreferenceCategory>
</PreferenceScreen>

View File

@ -1 +1 @@
3.10
3.11