超简陋浏览器_hta教程-查字典教程网
超简陋浏览器
超简陋浏览器
发布时间:2016-12-28 来源:查字典编辑
摘要:可是那些破站点让人太郁闷了...不是弹出广告,就是满屏幕飘浮动广告....气死我了...所以做了一个超简陋的浏览器,把页面中的JS基本上全禁...

可是那些破站点让人太郁闷了...不是弹出广告,就是满屏幕飘浮动广告....气死我了...

所以做了一个超简陋的浏览器,把页面中的JS基本上全禁掉了(禁用JS的正则不是很好,此外CSS里的没禁掉,不过目前反正够俺用就好了),顺便把iframe也全部干掉

还可以自动记得上次浏览的页面,打开就直接进入,看书的时候就不怕打断了

因为超简陋,所以连表单也不支持,只支持链接,哈哈,看书倒是够用了....

代码中的伪session处理和俺自己封装的xmlhttp值得一看

不能直接运行,保存到本地,另存为HTA使用,哈哈

复制代码 代码如下:

<head>

<title>BookViewer</title>

<metahttp-equiv="content-type"content="text/html;charset=UTF-8"/>

<style>

body{margin:0px;padding:0px;overflow:auto;border-style:none;font-size:12px;background-color:buttonface;}

iframe{width:100%;border-style:none;position:absolute;top:25px;}

#i1{height:22px;line-height:18px;width:100%;border:1pxsolid#666;margin:0px2px;padding:0px10px;}

</style>

<script>

strSessionName="bookviewer_lastURL";

lastURL="";

xp=newxmlhttp();

functioncheckMe(){

if(i1.value!=lastURL){

lastURL=i1.value;

session_set(strSessionName,lastURL);

}

try{

for(vari=0;i<f1.document.links.length;i++)f1.document.links[i].onclick=n0;

}catch(e){}

if(/book.5seecn/i.test(lastURL))f1.document.body.onkeydown=chkKey;

}

functionchkKey(){

varallLinks;

if(f1.event.keyCode==39){

allLinks=f1.document.links;

for(vari=0;i<allLinks.length;i++)if(/下一页/.test(allLinks[i].innerHTML)){

i1.value=allLinks[i].href;n2();return;

}

}elseif(f1.event.keyCode==37){

allLinks=f1.document.links;

for(vari=0;i<allLinks.length;i++)if(/上一页/.test(allLinks[i].innerHTML)){

i1.value=allLinks[i].href;n2();return;

}

}

}

functioninit(){

i1.onkeydown=function(){if(event.keyCode==13)n2();}

resizeWin();

i1.focus();

i1.select();

if(session_exists(strSessionName)){i1.value=session_get(strSessionName);n2();}

setInterval(checkMe,200);

}

functionresizeWin(){

document.getElementById("f1").style.height=document.body.clientHeight-25;

}

functionn0(){

n1(this.href);

return(false);

}

functionn1(str){

i1.value=str;

n2();

}

functionn2(){

str=i1.value;

if(i1=="")return;

if(!/^http:///i.test(str))str="http://"+str;

document.title="BookViewer-Loading...";

xp.open("get",str);

xp.onreadystatechange=n22;

xp.send("");

}

functionn22(){

varstr;

if(this.readyState==4){

if(this.status==200){

str=adodb_binary2string(this.getAttribute("responseBody"));

str=str.replace(/<script[sS]+?/script>/gi,"").replace(/<iframe[sS]+?/iframe>/gi,"").replace(/on(load|mouseover|mouseout|mousemove|focus|blur|keydown|keyup|keypress|change|readystatechange|click|dblclick|mousewheel)*=*"[sS]+?"/gi,"");

f1.document.open();

f1.document.write("<basehref=""+i1.value.substring(0,i1.value.lastIndexOf("/")+1)+""/>");

try{

f1.document.write(str);

}catch(e){}

f1.document.close();

f1.document.body.focus();

document.title="BookViewer-Ready";

}

}

}

functioncancelErr(){return(true);}

html_encode=function(strV){

return(strV.replace(/&/g,"&").replace(/"/g,""").replace(//g,"").replace(/t/g,"").replace(/</g,"<").replace(/>/g,">").replace(/rn/g,"<br>"));

}

functionadodb_binary2string(b){

varadodbStream=newActiveXObject("ADODB.Stream");

adodbStream.Type=1;//1=adTypeBinary

adodbStream.Open();

adodbStream.write(b);

adodbStream.position=0;

adodbStream.Type=2;

adodbStream.charset="_autodetect_all";

varre=adodbStream.readText();

adodbStream=null;

return(re);

}

functionsession_delete(strName){

varstr,reg,expt,dt;

if(!session_exists(strName))return;

strName=escape(strName);

strValue="";

dt=newDate();

dt.setYear(1980);

expt=";expires="+dt.toGMTString()+";";

str=strName+"="+strValue+expt;

document.cookie=str;

}

functionsession_get(strName){

varstr,reg;

str=document.cookie;

strName=escape(strName);

reg=newRegExp(strName+"=([^;]+)");

if(!reg.test(str))return;

return(unescape(str.match(reg)[1]));

}

functionsession_set(strName,strValue,blnExpireAfterClose){

varstr,reg,expt,dt;

strName=escape(strName);

strValue=escape(strValue);

dt=newDate();

dt.setYear(2099);

expt=blnExpireAfterClose?"":";expires="+dt.toGMTString()+";";

str=strName+"="+strValue+expt;

document.cookie=str;

}

functionsession_exists(strName){

varstr,reg;

str=document.cookie;

strName=escape(strName);

reg=newRegExp(strName+"=(.+);?");

if(!reg.test(str)){return(false);}else{return(true);}

}

functionxmlhttp(){

//declarealltheprivatevariable

vararyArgu,aryOnPropertyChange_AttachedEvents,aryRequestHeaders,blnAsyn,objRequest,objSelf,objThat,strMethod,strProtocol,strToBeSend,strUID,strUrl;

//declarealltheprivatefunctions

vardefaultEvent_onreadystatechange,getXMLRequester,init,realEvent_onreadystatechange,uid;

//declarepublicvariable

this.blnSendDefaultHeader=false;

this.readyState=0;

this.responseText="";

this.responseXML="";

this.status=-1;

//publicevent

this.onreadystatechange=defaultEvent_onreadystatechange;

//publicmethod

this.attachEvent=function(eventHandle,functionHandle){

vareventHandle=String(eventHandle).toLowerCase();

switch(eventHandle){

case"onreadystatechange":

if(this.onreadystatechange!=defaultEvent_onreadystatechange){

this.onreadystatechange=defaultEvent_onreadystatechange;

aryOnPropertyChange_AttachedEvents=newArray();

}

aryOnPropertyChange_AttachedEvents.push(functionHandle);

return(true);

break;

default:

return("Notreallizedyet.");

break;

}

}

this.deleteRequestHeader=function(strName){

deletearyRequestHeaders[strName];

}

this.detachEvent=function(eventHandle,functionHandle){

vareventHandle=String(eventHandle).toLowerCase();

switch(eventHandle){

case"onreadystatechange":

if(this.onreadystatechange!=defaultEvent_onreadystatechange){

this.onreadystatechange=defaultEvent_onreadystatechange;

aryOnPropertyChange_AttachedEvents=newArray();

return(true);

}

for(vari=0;i<aryOnPropertyChange_AttachedEvents.length;i++){

if(aryOnPropertyChange_AttachedEvents[i]==functionHandle){

aryOnPropertyChange_AttachedEvents.splice(i,1);

break;

}

}

return(true);

break;

default:

return("Notreallizedyet.");

break;

}

}

this.flush=function(){

try{this.readyState=objRequest.readyState;}catch(e){}

try{this.responseText=objRequest.responseText;}catch(e){}

try{this.responseXML=objRequest.responseXML;}catch(e){}

try{this.status=objRequest.status;}catch(e){}

}

this.getAllResponseHeaders=function(){

return(objRequest.getAllResponseHeaders());

}

this.getAttribute=function(strName,strRef){

switch(strName){

case"allHeaders":

return(objRequest.getAllResponseHeaders());

case"asyn":

return(blnAsyn);

case"header":

return(objRequest.getResponseHeader(strRef));

case"method":

return(strMethod);

case"protocol":

return(strProtocol);

case"readyState":

return(objRequest.readyState);

case"responseBody":

return(objRequest.responseBody);

case"responseText":

return(objRequest.responseText);

case"responseXML":

return(objRequest.responseXML);

case"send":case"sendString":case"strSend":

return(strToBeSend);

case"status":

return(objRequest.status);

case"uid":

return(strUID);

case"url":

return(strUrl);

default:

return(false);

}

}

this.getResponseHeader=function(strHeaderName){

return(objRequest.getResponseHeader(strHeaderName));

}

this.init=init;

this.open=function(method,url,asyn){

vartheURL;

strMethod=String(method).toLowerCase()=="POST"?"POST":"GET";

strUrl=String(url);

blnAsyn=String(asyn).toLowerCase()=="false"?false:true;

strProtocol=strUrl.match(/http:///i)?"http":"other";

theURL=strUrl

//if(strProtocol=="http")theURL=strUrl+(strUrl.indexOf(".")==-1?"/":"")+(strUrl.indexOf("?")==-1?"?":"&")+uid()+"=true";

objRequest.open(strMethod,theURL,blnAsyn);

}

this.reset=init;

this.send=function(strSend){

strToBeSend=String(strSend);

for(variinaryRequestHeaders){

objRequest.setRequestHeader(i,aryRequestHeaders[i]);

}

if(this.blnSendDefaultHeader){

objRequest.setRequestHeader("Content-Length",strToBeSend.length);

}

objRequest.onreadystatechange=realEvent_onreadystatechange;

objRequest.send(strToBeSend);

}

this.setRequestHeader=function(strName,strValue){

aryRequestHeaders[strName]=strValue;

}

//privatefunctions

functiondefaultEvent_onreadystatechange(){}

functiongetXMLRequester(){

varxmlhttp_request=false;

try{

if(window.ActiveXObject){

for(vari=5;i>-1;i--){

try{

if(i==2){

xmlhttp_request=newActiveXObject("Microsoft.XMLHTTP");

}else{

xmlhttp_request=newActiveXObject("Msxml2.XMLHTTP."+i+".0");

}

break;

}catch(e){

xmlhttp_request=false;

}

}

}elseif(window.XMLHttpRequest){

xmlhttp_request=newXMLHttpRequest();

}

}catch(e){

xmlhttp_request=false;

}

returnxmlhttp_request;

}

functioninit(){

//initprivatevariable

aryArgu=newArray();

aryOnPropertyChange_AttachedEvents=newArray();

aryRequestHeaders=newArray();

blnAsyn=true;

objRequest=getXMLRequester();

objSelf=this;

objThat=this;

strMethod="GET";

strProtocol="unknown";

strResponseText="";

strToBeSend="";

strUID=strUID?strUID:uid();

strUrl="";

//initpublicvariable

this.blnSendDefaultHeader=false;

//registthisobjecttowindow

window[strUID]=this;

}

functionrealEvent_onreadystatechange(){

objThat.flush();

if(objThat.onreadystatechange==defaultEvent_onreadystatechange){

for(vari=0;i<aryOnPropertyChange_AttachedEvents.length;i++){

try{

if(typeof(aryOnPropertyChange_AttachedEvents[i])=="function"){

aryOnPropertyChange_AttachedEvents[i].call(objThat);

}elseif(typeof(aryOnPropertyChange_AttachedEvents[i])=="string"){

eval(aryOnPropertyChange_AttachedEvents[i]);

}

}catch(e){alert("004"+e.description)}

}

}else{

try{

if(typeof(objThat.onreadystatechange)=="function"){

objThat.onreadystatechange();

}elseif(typeof(objThat.onreadystatechange)=="string"){

eval(objThat.onreadystatechange);

}

}catch(e){alert("005"+e.description)}

}

}

functionuid(){

return("u"+(newDate()).getTime().toString(35)+parseInt(Math.random()*999999).toString(35));

}

//doinit

this.init();

}

window.onload=init;

window.onresize=resizeWin;

window.onerror=cancelErr;

</script>

</head>

<body>

<inputid="i1"><br>

<iframeid="f1"></iframe>

</body>

相关阅读
推荐文章
猜你喜欢
附近的人在看
推荐阅读
拓展阅读
  • 大家都在看
  • 小编推荐
  • 猜你喜欢
  • 最新hta学习
    热门hta学习
    脚本专栏子分类