静态资源文件更新:

* index.html 移动到 assets 目录,首页通过 404.html 启动
* index.html 的部分功能移动到 sw 里,这样通过地址栏访问的 URL 也有纠错和补充功能
* tld 模块部分问题修复
* 404.html 加载动画
* 支持 HTTP refresh 头跳转 #70
* 修复单个 set-cookie 不生效的 BUG #71
* 地址栏补全 BUG 修复
* 修复 sw 主脚本路径未从 conf.js 读取的问题
This commit is contained in:
zjcqoo 2019-06-17 15:16:08 +08:00
parent ae50d5af2d
commit cac1eabae2
No known key found for this signature in database
GPG Key ID: 0867DB60BD24788F
8 changed files with 194 additions and 6 deletions

2
.gitignore vendored
View File

@ -1,3 +1,5 @@
._*
www
cert
nginx
*.sh

View File

@ -1 +1 @@
<body id=t>loading...<script>function r(){var e=Date.now();try{if(e-(+sessionStorage._ts||0)<100)return setTimeout(r,2e3);sessionStorage._ts=e}catch(t){}location.reload()}function i(e){t.innerHTML=e.message}!function e(){var n=navigator.serviceWorker;n&&self.ReadableStream?n.getRegistration().then(function(e){if(e)r();else{var t=location.href.split("-----")[0];n.register(t+"sw.js").then(r)["catch"](i)}}):t.innerHTML="请使用最新版 Chrome 浏览器访问"}()</script></body>
<html><head><meta charset=utf-8></head><body id=t><svg xmlns=http://www.w3.org/2000/svg width=100% height=100% viewBox="0 0 100 100"preserveAspectRatio=xMidYMid fill=none><circle cx=50 cy=50 r=25.944 stroke=#93dbe9><animate attributeName=r calcMode=spline values=0;40 keyTimes=0;1 dur=1 keySplines="0 0.2 0.8 1"begin=-0.5s repeatCount=indefinite stroke-width=2 /><animate attributeName=opacity calcMode=spline values=1;0 keyTimes=0;1 dur=1 keySplines="0.2 0 0.8 1"begin=-0.5s repeatCount=indefinite stroke-width=2 /></circle><circle cx=50 cy=50 r=40 stroke=#689cc5><animate attributeName=r calcMode=spline values=0;40 keyTimes=0;1 dur=1 keySplines="0 0.2 0.8 1"begin=0s repeatCount=indefinite stroke-width=2 /><animate attributeName=opacity calcMode=spline values=1;0 keyTimes=0;1 dur=1 keySplines="0.2 0 0.8 1"begin=0s repeatCount=indefinite stroke-width=2 /></circle></svg><script>function n(){var e=Date.now();try{var t=+sessionStorage._ts||0;if((sessionStorage._ts=e)-t<100)return setTimeout(n,5e3)}catch(r){}location.reload()}function r(e){a(e.message)}function a(e){t.innerHTML=e}!function o(){if(self.isSecureContext){var e=navigator.serviceWorker;e&&self.ReadableStream?e.register(function t(){return location.pathname.replace(/\/-+https?:.+/,"").replace(/\w+\.\w+$/,"").replace(/\/*$/,"/")}()+"sw.js").then(n)["catch"](r):a("请使用最新版 Chrome 浏览器访问")}else a("本程序需要 HTTPS 站点")}()</script></body></html>

View File

@ -1 +0,0 @@
该目录最终发布到 Web 服务器,或者 GitHub Pages例如 https://zjcqoo.github.io

File diff suppressed because one or more lines are too long

186
assets/index_v2.html Normal file
View File

@ -0,0 +1,186 @@
<!doctype html>
<html>
<head>
<title>Page Sandbox</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1.0,maximum-scale=1.0,user-scalable=0">
<base target="_blank">
<style>
body {
padding: 0 0.5em;
}
.box {
margin-top: 1em;
}
#txtURL {
width: 100%;
height: 2em;
text-indent: 0.5em;
padding: 0.25em 0;
}
#btnGo {
width: 100%;
font-size: 1.5em;
}
#list a {
margin: 1em;
}
</style>
</head>
<body>
<div class="box">
<input id="txtURL" type="text" value="www.google.com" autofocus>
</div>
<div class="box">
<button id="btnGo">Go</button>
</div>
<div class="box">
<span>切换线路:</span>
<select id="selNode"></select>
</div>
<div class="box" id="list">
</div>
<script>
const PAGE_CONF_SET = 110
const PAGE_CONF_GET = 111
const SW_CONF_RETURN = 112
const SW_CONF_CHANGE = 113
const PAGE_READY_CHECK = 200
const SW_READY = 201
const sw = navigator.serviceWorker
sw.addEventListener('message', onSwMsg)
sendMsgToSw(PAGE_READY_CHECK)
btnGo.onclick = function() {
const text = txtURL.value.trim()
if (text) {
const url = './-----' + text
const win = open(url)
win.opener = null
}
}
txtURL.onkeypress = function(e) {
if (e.keyCode === 13) {
btnGo.onclick()
}
}
txtURL.setSelectionRange(0, txtURL.value.length)
function onSwMsg(e) {
const [cmd, msg] = e.data
switch (cmd) {
case SW_CONF_RETURN:
conf = msg
showConf()
break
case SW_CONF_CHANGE:
conf = msg
updateSelected()
break
case SW_READY:
console.log('sw ready')
showIcons()
sendMsgToSw(PAGE_CONF_GET)
break
}
}
function onSwFail(err) {
txtURL.value = err
}
selNode.onchange = function() {
const item = this.options[this.selectedIndex]
const node = item.value
conf.node_default = node
sendMsgToSw(PAGE_CONF_SET, conf)
}
function sendMsgToSw(cmd, val) {
const ctl = sw.controller
if (!ctl) {
console.log('ctl is null')
return
}
ctl.postMessage([cmd, val])
}
const SITE_LIST = [
['google', ''],
['youtube', ''],
['twitter', 'twitter.com/google'],
['flickr', ''],
['quora', 'www.quora.com/topic/JavaScript-programming-language'],
['twitch', 'www.twitch.tv/'],
['reddit', ''],
['wiki', 'zh.wikipedia.org/'],
['gist', 'gist.github.com/'],
['facebook', 'facebook.com/Google/'],
['blogger', ''],
]
function showIcons() {
list.innerHTML = SITE_LIST.map(v => {
let [id, url] = v
url = url || `www.${id}.com/`
return `\
<a rel=noopener href=./-----https://${url}>\
<img width=128 height=128 src=__sys__/assets/ico/${id}.png></a>`
}).join('')
}
function addNodeItem(id, text) {
const optEl = document.createElement('option')
optEl.id = '--' + id
optEl.text = text
optEl.value = id
selNode.appendChild(optEl)
}
function updateSelected() {
const id = conf.node_default
const item = document.getElementById('--' + id)
if (item) {
item.selected = true
} else {
console.warn('unknown node:', id)
}
}
function parseTestNode() {
if (location.port === '8443' || location.port === '8080') {
const host = location.host
conf.node_map[host] = {
label: host,
lines: [host]
}
conf.node_default = host
sendMsgToSw(PAGE_CONF_SET, conf)
}
}
function showConf() {
parseTestNode()
const nodeMap = conf.node_map
Object.keys(nodeMap).forEach(id => {
const info = nodeMap[id]
if (info.hidden) {
return
}
addNodeItem(id, info.label)
})
updateSelected()
}
</script>
</body>
</html>

View File

@ -1,6 +1,6 @@
jsproxy_config({
// 当前配置的版本(服务端记录在日志中,方便排查问题)
ver: '51',
ver: '52',
// 节点配置
node_map: {
@ -9,7 +9,8 @@ jsproxy_config({
lines: [
// 多条线路,负载均衡系统会从其中选一条
'node-aliyun-hk-0.etherdream.com:8443',
'node-aliyun-hk-1.etherdream.com:8443'
'node-aliyun-hk-1.etherdream.com:8443',
'node-aliyun-hk-2.etherdream.com:8443',
]
},
'aliyun-sg': {

View File

@ -1 +0,0 @@
<!doctypehtml><html><head><title>Page Sandbox</title><meta charset=utf-8><meta name=viewport content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=0"><base target=_blank><style>body{padding:0 .5em}.box{margin-top:1em}#txtURL{width:100%;height:2em;text-indent:.5em;padding:.25em 0}#btnGo{width:100%;font-size:1.5em}#list a{margin:1em}</style></head><body><div class=box><input id=txtURL value=www.google.com autofocus></div><div class=box><button id=btnGo disabled=disabled>初始化中...</button></div><div class=box><span>切换线路:</span> <select id=selNode disabled=disabled></select></div><div class=box id=list></div><script>var i=110,r=111,l=112,s=113,e=200,u=201,n=navigator.serviceWorker;function c(){return location.pathname.replace(/\w+\.\w+$/,"").replace(/\/*$/,"/")}function t(){selNode.disabled=!1,n.addEventListener("message",o),setTimeout(f,20,e)}function o(e){var t=e.data,o=t[0],n=t[1];switch(o){case l:conf=n,function c(){!function t(){if("8443"===location.port||"8080"===location.port){var e=location.host;conf.node_map[e]={label:e,lines:[e]},conf.node_default=e,f(i,conf)}}();var o=conf.node_map;Object.keys(o).forEach(function(e){var t=o[e];t.hidden||function n(e,t){var o=document.createElement("option");o.id="--"+e,o.text=t,o.value=e,selNode.appendChild(o)}(e,t.label)}),g()}();break;case s:conf=n,g();break;case u:console.log("sw ready"),function a(){list.innerHTML=d.map(function(e){var t=e[0],o=e[1]||"www."+t+".com";return"<a rel=noopener href=./-----https://"+o+"><img width=128 height=128 src=assets/ico/"+t+".png></a>"}).join("")}(),f(r)}}function a(e){txtURL.value=e}function f(e,t){var o=n.controller;o?o.postMessage([e,t]):console.log("ctl is null")}btnGo.onclick=function(){var e=txtURL.value.trim();0<=e.indexOf("-----")&&(e=e.split("-----").pop(),txtURL.value=e);var t=function o(e){return c()+"-----"+e}(function n(e){return/^https?:\/\//i.test(e)?e:/\.(com|cn|net|org|tv)$/.test(e)?"https://"+e:"https://www.google.com/search?q="+encodeURIComponent(e)}(e));open(t).opener=null},txtURL.onkeypress=function(e){13===e.keyCode&&btnGo.onclick()},txtURL.setSelectionRange(0,txtURL.value.length),selNode.onchange=function(){var e=this.options[this.selectedIndex].value;conf.node_default=e,f(i,conf)};var d=[["google",""],["youtube",""],["twitter","twitter.com/google"],["flickr",""],["quora","www.quora.com/topic/JavaScript-programming-language"],["twitch","www.twitch.tv"],["reddit",""],["wiki","zh.wikipedia.org"],["gist","gist.github.com"],["facebook","facebook.com/Google/"],["blogger",""]];function g(){var e=conf.node_default,t=document.getElementById("--"+e);t?t.selected=!0:console.warn("unknown node:",e)}!function p(){console.log("JsProxy v0.0.10 https://github.com/EtherDream/jsproxy/"),self.isSecureContext?n&&self.ReadableStream?(btnGo.disabled=!1,btnGo.textContent="Go",function e(){n.getRegistration().then(function(e){e?t():n.register(c()+"sw.js").then(function(e){return n.ready}).then(t)["catch"](a)})}()):txtURL.value="浏览器版本过低,推荐使用最新版 Chrome 浏览器":txtURL.value="本程序需要 HTTPS 站点"}()</script></body></html>

2
sw.js
View File

@ -1 +1 @@
importScripts(__FILE__='https://cdn.jsdelivr.net/gh/etherdream/jsproxy@gh-pages/assets/bundle.b30fe48b.js')
jsproxy_config=x=>importScripts(__FILE__=x.assets_cdn+'bundle.e325af85.js');importScripts('conf.js')