Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangyuecn committed Sep 19, 2022
1 parent 109923f commit 131c1eb
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ iOS Demo App :[下载源码](https://github.com/xiangyuecn/Recorder/tree/maste

> https环境搭建最佳实践:建议给自己的域名申请一个泛域名通配符证书(*.xxx.com),然后线上、本地开发均可使用此证书;本地开发环境直接分配一个二级域名(dev.xxx.com、local.xxx.com、192-168-1-123.xxx.com)解析A记录到电脑局域网的IP地址(192.168.1.123、127.0.0.1),方便本地开发跨端调试(本地如何配置https请针对自己的开发环境自行搜索,很容易)。
>
> 泛域名通配符证书推荐在线免费申请:[ZeroSSL](https://zerossl.com/)[Let’s Encrypt](https://letsencrypt.org/);不建议自己生成根证书来签发域名证书,一个是流程复杂,每个设备均要导入根证书,致命的是很多现代浏览器不再信任用户目录下导入的根证书(Android)。
> 泛域名通配符证书推荐在线免费申请:[ZeroSSLLet’s Encrypt](https://xiangyuecn.gitee.io/acme-html-web-browser-client/ACME-HTML-Web-Browser-Client.html);不建议自己生成根证书来签发域名证书,一个是流程复杂,每个设备均要导入根证书,致命的是很多现代浏览器不再信任用户目录下导入的根证书(Android)。

## 【1】加载框架
Expand Down
65 changes: 43 additions & 22 deletions assets/zdemo.widget.donate.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,13 @@ var DonateWidget=function(set){
};
var Fn=function(set){
this.set={
log:function(htmlMsg){}
,mobElem:null
log:function(htmlMsg){} //自定义显示日志消息,返回false禁止控制台输出
,mobElem:null //移动端时显示到这个dom对象里,空不显示

,viewOnly:false //仅显示,不提供关闭,点击页面按钮不弹框
,getTitle:function(title){} //自定义大标题html,返回空将使用默认
,getBtn:function(btn,val){} //自定义按钮名称html,返回空间使用默认;btn=0关闭 1已打赏
,onBtnClick:function(btn,isDialog,isFloat){} //当点击按钮时回调,返回false阻止默认动作
};
for(var k in set){
this.set[k]=set[k];
Expand All @@ -23,30 +28,36 @@ var Fn=function(set){
DonateWidget.cur=This;

This.view();
window.addEventListener&&document.body.addEventListener("click",function(e){
if(/button/i.test(e.target.tagName) || /btn/i.test(e.target.className)){
try{
This.dialog();
}catch(e){}
};
});
if(!this.set.viewOnly&&window.addEventListener){
document.body.addEventListener("click",function(e){
if(/button/i.test(e.target.tagName) || /btn/i.test(e.target.className)){
try{
This.dialog();
}catch(e){}
};
});
};
};
Fn.prototype=DonateWidget.prototype={
log:function(htmlMsg){
htmlMsg='[打赏挂件]'+htmlMsg;
console.log(htmlMsg.replace(/<[^<>]+?>/g,""));
this.set.log(htmlMsg);
var val=this.set.log(htmlMsg);
if(val!==false){
console.log(htmlMsg.replace(/<[^<>]+?>/g,""));
}
}
,view:function(){
if(IsMobile){
if(this.set.mobElem){
this._render(false,false,this.set.mobElem);
};
}else{
var dis=localStorage["DonateWidget_SetDisable"];
if(dis && Date.now()-new Date(dis).getTime()<24*60*60*1000){
this.log('已禁用打赏挂件一天,可通过命令开启:DonateWidget.SetDisable(0) <a href="" onclick="DonateWidget.SetDisable(0);return false">exec</a>');
return;
if(!this.set.viewOnly){
var dis=localStorage["DonateWidget_SetDisable"];
if(dis && Date.now()-new Date(dis).getTime()<24*60*60*1000){
this.log('已禁用打赏挂件一天,可通过命令开启:DonateWidget.SetDisable(0) <a href="" onclick="DonateWidget.SetDisable(0);return false">exec</a>');
return;
};
};

this.dialog(0,"Float");
Expand Down Expand Up @@ -76,7 +87,7 @@ Fn.prototype=DonateWidget.prototype={
var fixedElem=document.createElement("div");
fixedElem.innerHTML='\
<div class="DonateWidget_dialog'+(_f||"Box")+'" style="z-index:'+zIndex+';position: fixed;display:flex;align-items:center;justify-content:center;'+(_f?'top:20%;right:5px':'left:0;top:0;width:100%;height:100%;background:rgba(0,0,0,0.3)')+'">\
<div onclick="DonateWidget.cur.close(1,\''+(_f||"Box")+'\')" style="position: absolute;font-size:32px;cursor: pointer;top: 0;right:8px;color:#fff;">'+(_f?'×':'')+'</div>\
<div onclick="DonateWidget.cur.close(1,\''+(_f||"Box")+'\')" style="position: absolute;font-size:32px;cursor: pointer;top: 0;right:8px;color:#fff;" class="DonateWidget_XCloseBtn">'+(_f&&!this.set.viewOnly?'×':'')+'</div>\
<div class="DonateWidget_dialogRender"></div>\
</div>';
document.body.appendChild(fixedElem);
Expand All @@ -90,7 +101,7 @@ Fn.prototype=DonateWidget.prototype={
for(var i=0;!title&&i<times.length;i++){
var time=new Date(times[i]).getTime();
var td=Math.ceil((time-now)/24/60/60/1000);
if(td<=45&&td>-25){
if(td<=20&&td>-20){
if(td>0){
title="剩余"+td+"天就过年了,给大伙拜个早年吧~ 赏包辣条?";
}else{
Expand All @@ -106,18 +117,23 @@ Fn.prototype=DonateWidget.prototype={
};
};
title=title||"赏包辣条?";
title=this.set.getTitle(title)||title;
var btn0=(isDialog?"再看吧,关掉先":"算了吧")+unescape("%uD83D%uDE36");
btn0=this.set.getBtn(0,btn0)||btn0;
var btn1='已打赏~ 壕气'+unescape("%uD83D%uDE18");
btn1=this.set.getBtn(1,btn1)||btn1;

var min=IsMobile?true:isDialog?false:true;
elem.innerHTML='\
<div style="border-radius:12px;background:linear-gradient(160deg, rgba(0,179,255,'+(isFloat?".7":"1")+') 20%, rgba(177,0,255,'+(isFloat?".7":"1")+') 80%);max-width:'+(min?300:520)+'px;padding:'+(min?20:30)+'px;text-align: center;">\
<div style="font-size:18px;color:#fff;">'+title+'</div>\
<div class="DonateWidget_render" style="border-radius:12px;background:linear-gradient(160deg, rgba(0,179,255,'+(isFloat?".7":"1")+') 20%, rgba(177,0,255,'+(isFloat?".7":"1")+') 80%);max-width:'+(min?300:520)+'px;padding:'+(min?20:30)+'px;text-align: center;">\
<div style="font-size:18px;color:#fff;" class="DonateWidget_Title">'+title+'</div>\
<div style="padding-top:14px">\
<img src="'+ImgAlipay+'" style="width:'+(min?145:220)+'px">\
<img src="'+ImgWeixin+'" style="width:'+(min?145:220)+'px">\
</div>\
<div style="padding-top:10px">\
<button onclick="DonateWidget.cur.click(0,'+(isDialog?1:0)+','+(isFloat?1:0)+')" class="DonateWidget_Btn" style="margin-right:'+(min?10:40)+'px">'+(isDialog?"再看吧,关掉先":"算了吧")+unescape("%uD83D%uDE36")+'</button>\
<button onclick="DonateWidget.cur.click(1,'+(isDialog?1:0)+','+(isFloat?1:0)+')" class="DonateWidget_Btn">已打赏~ 壕气'+unescape("%uD83D%uDE18")+'</button>\
<button onclick="DonateWidget.cur.click(0,'+(isDialog?1:0)+','+(isFloat?1:0)+')" class="DonateWidget_Btn DonateWidget_Btn_0" style="margin-right:'+(min?10:40)+'px">'+btn0+'</button>\
<button onclick="DonateWidget.cur.click(1,'+(isDialog?1:0)+','+(isFloat?1:0)+')" class="DonateWidget_Btn DonateWidget_Btn_1">'+btn1+'</button>\
</div>\
<style>\
.DonateWidget_Btn{\
Expand All @@ -141,11 +157,16 @@ Fn.prototype=DonateWidget.prototype={
}
,click:function(ok,isDialog,isFloat){
localStorage["DonateWidget_Close"]=new Date().toDateString();
if(this.set.onBtnClick(ok,isDialog,isFloat)===false){
return;
}
if(isDialog){
this.close(1,"Box");
}else if(isFloat){
this.close(!ok,"Float");
ok&&DonateWidget.SetDisable(1);
if(!this.set.viewOnly){
ok&&DonateWidget.SetDisable(1);
}
};

if(ok){
Expand Down
55 changes: 35 additions & 20 deletions assets/工具-GitHub页面历史版本访问.html
Original file line number Diff line number Diff line change
Expand Up @@ -178,27 +178,34 @@
}
var url="https://cdn.jsdelivr.net/gh/"+urlInfo.owner+"/"+urlInfo.repo+"/";
reclog('正在拉取版本号列表... [sync]'+ToA(url),"#bbb");
Load(url,function(txt){
var loadEnd=function(txt){
txt=txt.replace(/\r|\n/g,"");
var vers=[],opts=[];
var m=/<select[^>]*versions\b.+?<\/select/.exec(txt);
if(!m){
reclog("版本号页面已拉取,但提取列表失败,正则表达式未匹配");
return;
};
txt=m[0];
var exp=/<option.+?@([^"]+)"/g,vers=[],opts=[];
while(m=exp.exec(txt)){
vers.push(m[1]);
opts.push('<option value="'+m[1]+'">'+m[1]+'</option>');
};
if(!vers.length){
reclog("版本号页面已拉取,但未发现任何版本号,可能是此仓库没有任何Releases");
return;
if(txt=="-1"){
//NOOP
}else if(!m){
reclog("版本号页面已拉取,但未匹配到版本号列表,可能是此仓库没有任何Releases",3);
}else{
txt=m[0];
var exp=/<option.+?@([^"]+)"/g;
while(m=exp.exec(txt)){
vers.push(m[1]);
opts.push('<option value="'+m[1]+'">'+m[1]+'</option>');
};
if(!vers.length){
reclog("版本号页面已拉取,但未发现任何版本号,可能是此仓库没有任何Releases",3);
}else{
console.log("版本号列表",vers);
reclog("版本号列表加载完成,发现"+vers.length+"个版本");
}
};
console.log("版本号列表",vers);
reclog("版本号列表加载完成,发现"+vers.length+"个版本");

args_ver=args_ver||vers[0];
if(!args_ver){
reclog("未提供版本号参数,已终止处理。",3);
return;
}
rootUrl="https://cdn.jsdelivr.net/gh/"+urlInfo.owner+"/"+urlInfo.repo+"@"+args_ver;

var slcVer=args_ver;//下拉选中的值
Expand All @@ -223,8 +230,10 @@
+'<div class="div_'+id+'"></div>');

Step_LoadPage();
},function(err){
};
Load(url,loadEnd,function(err){
reclog("拉取列表失败:"+err,"red;font-size:30px");
loadEnd("-1");
},true);
};

Expand Down Expand Up @@ -276,7 +285,7 @@
var div=document.createElement("div");
var elem=document.querySelector(".OldVer_Logs");
elem.appendChild(div);
div.innerHTML='<div style="color:'+(!color?"":color==1?"red":color==2?"#0b1":color)+'">['+t+']'+s+'</div>';
div.innerHTML='<div style="color:'+(!color?"":color==1?"red":color==2?"#0b1":color==3?"#f90":color)+'">['+t+']'+s+'</div>';
};
function ToA(url,txt){
return '<a href="'+url+'" target="_blank">'+(txt||url)+'</a>';
Expand All @@ -286,8 +295,10 @@
var xhr=new XMLHttpRequest();
oldOpen.call(xhr,"GET", url, !sync);
if(!sync)xhr.timeout=30000;
var end=0;
xhr.onreadystatechange=function(){
if(xhr.readyState==4){
if(!end && xhr.readyState==4){
end=1;
if(xhr.status<200 || xhr.status>299){
var msg="请求失败["+xhr.status+"]";
console.error(msg+" "+url,xhr);
Expand All @@ -297,7 +308,11 @@
}
}
};
xhr.send();
try{
xhr.send();
}catch(e){
xhr.onreadystatechange();
}
};

Step_LoadVers();
Expand Down

0 comments on commit 131c1eb

Please sign in to comment.