增加自定义主页
This commit is contained in:
parent
20496e0657
commit
2ce86fae22
|
@ -2,7 +2,7 @@
|
|||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.hty.browser"
|
||||
android:versionCode="4"
|
||||
android:versionName="4.34">
|
||||
android:versionName="4.35">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <!-- 查询网络状态权限 -->
|
||||
|
|
|
@ -9,7 +9,7 @@ p { text-indent:2em; }
|
|||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.34</h2>
|
||||
<h2 align=center><img src=logo.png><br>海天鹰浏览器 V4.35</h2>
|
||||
<p>内置扩展的浏览器。</p>
|
||||
<p>扩展:链接关键字过滤,链接关键字高亮,图片自定义过滤,视频独立播放。</p>
|
||||
<p>作者:海天鹰</p>
|
||||
|
@ -23,6 +23,7 @@ p { text-indent:2em; }
|
|||
<p><a href="https://stackoverflow.com/questions/3462582/display-the-android-webviews-favicon" target="_blank">获取网页图标</a></p>
|
||||
<p><a href="https://www.jianshu.com/p/c9a18050a249" target="_blank">字符串转Bitmap</a></p>
|
||||
<h3>更新日志:</h3>
|
||||
<h3>V4.35 (2024-03-16)</h3><ol><li>增加自定义主页。</li></ol>
|
||||
<h3>V4.34 (2024-01-30)</h3><ol><li>增加hash链接转magnet。</li></ol>
|
||||
<h3>V4.33 (2024-01-19)</h3><ol><li>收藏夹分类:使用下拉列表代替单选组。</li></ol>
|
||||
<h3>V4.32 (2023-11-19)</h3><ol><li>增加GIF屏蔽。</li><li>在Activity中处理广告屏蔽规则。</li></ol>
|
||||
|
|
|
@ -0,0 +1,169 @@
|
|||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"/>
|
||||
<title>主页</title>
|
||||
</head>
|
||||
<style>
|
||||
a { text-decoration:none; }
|
||||
span { display:inline-block; margin:5px; }
|
||||
a, img { -webkit-user-drag:none; }
|
||||
img { vertical-align:middle; }
|
||||
.operation { color:white; }
|
||||
.operation:hover { cursor:hand; color:black; }
|
||||
.menu { position:absolute; background:white; border:1px solid gray; width:100px; display:none; }
|
||||
.menu div:hover { background:#ddd; }
|
||||
#list a { margin:20px; width:50px; height:50px; display: inline-block; }
|
||||
#list button { margin:20px; width:50px; height:50px; font-size:40px; vertical-align:bottom; }
|
||||
</style>
|
||||
<body>
|
||||
<center><img src="logo.png"></center>
|
||||
<div align="center">
|
||||
<select id="search_engine">
|
||||
<option value="https://www.baidu.com/s?wd=%s">百度</option>
|
||||
<option value="https://cn.bing.com/search?q=%s">必应</option>
|
||||
<option value="https://www.sogou.com/tx?query=%s">搜搜</option>
|
||||
<option value="https://www.so.com/s?q=%s">360搜索</option>
|
||||
</select>
|
||||
<input type="text" id="search_word">
|
||||
<button id="button_search">搜索</button>
|
||||
</div>
|
||||
<div id="list"></div>
|
||||
<div id="menu" class="menu"><div id="menu_modify">修改</div><div id="menu_delete">删除</div></div>
|
||||
<dialog id="dialog">
|
||||
<h2 align="center" id="type"></h2>
|
||||
<input type="text" id="title" placeholder="标题" value=""><p>
|
||||
<input type="text" id="website" placeholder="https://" value="https://"><p>
|
||||
<center><button id="button_confirm">确定</button> <button id="button_cancel">取消</button></center>
|
||||
</dialog>
|
||||
<script>
|
||||
var json, id, timer, title1, website1, type1;
|
||||
if (!localStorage.webfav)
|
||||
localStorage.webfav = '[]';
|
||||
var webfav = localStorage.webfav;
|
||||
|
||||
document.addEventListener('contextmenu', function(e){
|
||||
e.preventDefault();
|
||||
});
|
||||
|
||||
document.addEventListener('click', function(e){
|
||||
var rect = menu.getBoundingClientRect();
|
||||
if (e.pageX < rect.left || e.pageX > rect.right || e.pageY < rect.top || e.pageY > rect.bottom){
|
||||
menu.style.display = 'none';
|
||||
}
|
||||
});
|
||||
|
||||
function genList() {
|
||||
json = JSON.parse(localStorage.webfav);
|
||||
list.innerHTML = '';
|
||||
for (var i=0; i<json.length; i++) {
|
||||
var a = document.createElement('a');
|
||||
a.href = json[i].website;
|
||||
a.target = '_blank';
|
||||
var img = document.createElement('img');
|
||||
img.src = json[i].website + '/favicon.ico';
|
||||
img.style.width = '50px';
|
||||
img.style.height = '50px';
|
||||
img.title = json[i].title;
|
||||
img.alt = json[i].title;
|
||||
|
||||
//长按菜单,https://www.5axxw.com/questions/simple/nyzvs3
|
||||
img.addEventListener('contextmenu', function(e){
|
||||
e.preventDefault(); // 阻止默认的右键菜单弹出
|
||||
});
|
||||
//通过时间间隔区分点击和长按,https://www.jianshu.com/p/b05d3d5d5e81
|
||||
(function(i){
|
||||
img.addEventListener('mousedown', function(e){
|
||||
timer = setTimeout(function(){
|
||||
menu.style.display = 'block';
|
||||
menu.style.left = e.pageX + 'px';
|
||||
menu.style.top = e.pageY + 'px';
|
||||
id = i;
|
||||
title1 = json[i].title;
|
||||
website1 = json[i].website;
|
||||
}, 500);
|
||||
});
|
||||
var t, time;
|
||||
img.addEventListener('touchstart', function(e){
|
||||
e.preventDefault();
|
||||
t = e.touches[0];
|
||||
time = Date.now();
|
||||
});
|
||||
img.addEventListener('touchend', function(e){
|
||||
var dt = Date.now() - time;
|
||||
if (dt < 300)
|
||||
window.location.href = json[i].website;
|
||||
else {
|
||||
menu.style.display = 'block';
|
||||
menu.style.left = t.pageX + 'px';
|
||||
menu.style.top = t.pageY + 'px';
|
||||
id = i;
|
||||
title1 = json[i].title;
|
||||
website1 = json[i].website;
|
||||
}
|
||||
});
|
||||
})(i);
|
||||
img.addEventListener('mouseup', function(e){
|
||||
clearTimeout(timer);
|
||||
});
|
||||
a.appendChild(img);
|
||||
list.appendChild(a);
|
||||
}
|
||||
var button = document.createElement('button');
|
||||
button.textContent = '+';
|
||||
button.onclick = function(){
|
||||
type.textContent = '添加';
|
||||
type1 = 0;
|
||||
title.value = '';
|
||||
website.value = 'https://';
|
||||
dialog.showModal();
|
||||
};
|
||||
list.appendChild(button);
|
||||
}
|
||||
|
||||
button_search.addEventListener('click', function(){
|
||||
var url = search_engine.options[search_engine.selectedIndex].value.replace('%s', search_word.value);
|
||||
window.open(url, "_blank");
|
||||
});
|
||||
|
||||
menu_modify.addEventListener('click', function(){
|
||||
menu.style.display = 'none';
|
||||
title.value = title1;
|
||||
website.value = website1;
|
||||
type.textContent = '修改';
|
||||
type1 = 1;
|
||||
dialog.showModal();
|
||||
});
|
||||
|
||||
menu_delete.addEventListener('click', function(){
|
||||
menu.style.display = 'none';
|
||||
json = JSON.parse(localStorage.webfav);
|
||||
json.splice(id, 1);
|
||||
localStorage.webfav = JSON.stringify(json);
|
||||
genList();
|
||||
});
|
||||
|
||||
button_confirm.addEventListener('click', function(e){
|
||||
dialog.close();
|
||||
if (type1 == 0) {
|
||||
json = JSON.parse(localStorage.webfav);
|
||||
json.push({
|
||||
'title': title.value,
|
||||
'website': website.value
|
||||
});
|
||||
} else if (type1 == 1) {
|
||||
json[id].title = title.value;
|
||||
json[id].website = website.value;
|
||||
}
|
||||
localStorage.webfav = JSON.stringify(json);
|
||||
genList();
|
||||
});
|
||||
|
||||
button_cancel.addEventListener('click', function(e){
|
||||
dialog.close();
|
||||
});
|
||||
|
||||
genList();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
|
@ -21,6 +21,7 @@ import java.util.ArrayList;
|
|||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
|
@ -693,12 +694,18 @@ public class MainActivity extends Activity {
|
|||
dialog.dismiss();
|
||||
switch (which) {
|
||||
case 0:
|
||||
newWindow(sharedPreferences.getString("homepage", "http://www.baidu.com"));
|
||||
String surl = sharedPreferences.getString("homepage", "file:///android_asset/home.htm");
|
||||
if (surl.equals(""))
|
||||
surl = "file:///android_asset/home.htm";
|
||||
newWindow(surl);
|
||||
break;
|
||||
case 1:
|
||||
list_webView.remove(currentPage);
|
||||
if (list_webView.size() == 0) {
|
||||
newWindow(sharedPreferences.getString("homepage", "http://www.baidu.com"));
|
||||
surl = sharedPreferences.getString("homepage", "file:///android_asset/home.htm");
|
||||
if (surl.equals(""))
|
||||
surl = "file:///android_asset/home.htm";
|
||||
newWindow(surl);
|
||||
} else {
|
||||
if (currentPage == list_webView.size())
|
||||
currentPage--;
|
||||
|
@ -1471,7 +1478,10 @@ public class MainActivity extends Activity {
|
|||
urln = intent.getDataString();
|
||||
newWindow(urln);
|
||||
} else {
|
||||
newWindow(sharedPreferences.getString("homepage", "http://www.baidu.com"));
|
||||
String surl = sharedPreferences.getString("homepage", "file:///android_asset/home.htm");
|
||||
if (surl.equals(""))
|
||||
surl = "file:///android_asset/home.htm";
|
||||
newWindow(surl);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1491,7 +1501,7 @@ public class MainActivity extends Activity {
|
|||
String filename = surl.substring(surl.lastIndexOf("/") + 1);
|
||||
Log.e(Thread.currentThread().getStackTrace()[2] + " ", "FileName: " + filename);
|
||||
if (filename.contains("&f=JPEG?")) { //百度网页图片重命名
|
||||
SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss");
|
||||
SimpleDateFormat SDF = new SimpleDateFormat("yyyyMMddHHmmss", Locale.getDefault());
|
||||
Date date = new Date();
|
||||
String stime = SDF.format(date);
|
||||
filename = stime + ".jpg";
|
||||
|
|
|
@ -27,7 +27,7 @@ public class SettingsActivity extends PreferenceActivity implements OnSharedPref
|
|||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
ETP_homepage.setSummary(SP.getString("homepage", "http://www.baidu.com"));
|
||||
ETP_homepage.setSummary(SP.getString("homepage", ""));
|
||||
ETP_filter.setSummary(SP.getString("filter", ""));
|
||||
ETP_highlight.setSummary(SP.getString("highlight", ""));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue