脚本宝典收集整理的这篇文章主要介绍了超简陋浏览器,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
可是那些破站点让人太郁闷了...不是弹出广告,就是满屏幕飘浮动广告....气死我了...
所以做了一个超简陋的浏览器,把页面中的 JS 基本上全禁掉了(禁用JS的正则不是很好,此外CSS里的没禁掉,不过目前反正够俺用就好了),顺便把 iframe 也全部干掉
还可以自动记得上次浏览的页面,打开就直接进入,看书的时候就不怕打断了
因为超简陋,所以连 表单也不支持,只支持链接,哈哈,看书倒是够用了....
代码中的 伪session 处理 和 俺自己封装的 xmlhttp 值得一看
不能直接运行,保存到本地,另存为 HTA 使用,哈哈
<head>
<title>Book Viewer</title>
<meta http-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:1px solid #666; margin:0px 2px; padding:0px 10px; }
</style>
<script>
strSessionName="bookviewer_lastURL";
lastURL="";
xp=new xmlhttp();
function checkMe(){
if(i1.value!=lastURL){
lastURL=i1.value;
session_set(strSessionName,lastURL);
}
try{
for(var i=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;
}
function chkKey(){
var allLinks;
if(f1.event.keyCode==39){
allLinks=f1.document.links;
for(var i=0;i<allLinks.length;i++)if(/下一页/.test(allLinks[i].innerHTML)){
i1.value=allLinks[i].href; n2(); return;
}
}else if(f1.event.keyCode==37){
allLinks=f1.document.links;
for(var i=0;i<allLinks.length;i++)if(/上一页/.test(allLinks[i].innerHTML)){
i1.value=allLinks[i].href; n2(); return;
}
}
}
function init(){
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);
}
function resizeWin(){
document.getElementById("f1").style.height=document.body.clientHeight-25;
}
function n0(){
n1(this.href);
return(false);
}
function n1(str){
i1.value=str;
n2();
}
function n2(){
str=i1.value;
if(i1=="")return;
if(!/^http:\/\//i.test(str))str="http://"+str;
document.title="Book Viewer - Loading...";
xp.open("get",str);
xp.onreadystatechange=n22;
xp.send("");
}
function n22(){
var str;
if(this.readyState==4){
if(this.status==200){
str=adodb_binary2string(this.getAttribute("responseBody"));
str=str.replace(/<script[\s\S]+?\/script>/gi,"").replace(/<iframe[\s\S]+?\/iframe>/gi,"").replace(/on(load|mouseover|mouseout|mousemove|focus|blur|keydown|keyup|keypress|change|readystatechange|click|dblclick|mousewheel) *= *\"[\s\S]+?\"/gi,"");
f1.document.open();
f1.document.write("<base href=\""+i1.value.substring(0,i1.value.lastIndexOf("/")+1)+"\" \/>");
try{
f1.document.write(str);
}catch(e){}
f1.document.close();
f1.document.body.focus();
document.title="Book Viewer - Ready";
}
}
}
function cancelErr(){ return(true); }
html_encode=function(strV){
return(strV.replace(/&/g,"&").replace(/"/g,""").replace(/ /g," ").replace(/\t/g," ").replace(/</g,"<").replace(/>/g,">").replace(/\r\n/g,"<br>"));
}
function adodb_binary2string(b){
var adodbStream=new ActiveXObject("ADODB.Stream");
adodbStream.Type=1;//1=adTypeBinary
adodbStream.Open();
adodbStream.write(b);
adodbStream.position=0;
adodbStream.Type=2;
adodbStream.charset="_autodetect_all";
var re=adodbStream.readText();
adodbStream=null;
return(re);
}
function session_delete(strName){
var str, reg, expt, dt;
if(!session_exists(strName))return;
strName=escape(strName);
strValue="";
dt=new Date();
dt.setYear(1980);
expt=";expires="+dt.toGMTString()+";";
str=strName+"="+strValue+expt;
document.cookie=str;
}
function session_get(strName){
var str, reg;
str=document.cookie;
strName=escape(strName);
reg=new RegExp(strName+"=([^;]+)");
if(!reg.test(str))return;
return(unescape(str.match(reg)[1]));
}
function session_set(strName,strValue,blnExpireAfterClose){
var str, reg, expt, dt;
strName=escape(strName);
strValue=escape(strValue);
dt=new Date();
dt.setYear(2099);
expt=blnExpireAfterClose?"":";expires="+dt.toGMTString()+";";
str=strName+"="+strValue+expt;
document.cookie=str;
}
function session_exists(strName){
var str, reg;
str=document.cookie;
strName=escape(strName);
reg=new RegExp(strName+"=(.+);?");
if(!reg.test(str)){return(false);}else{return(true);}
}
function xmlhttp(){
// declare all the private variable
var aryArgu, aryOnPropertyChange_AttachedEvents, aryRequestHeaders, blnAsyn, objRequest, objSelf, objThat, strMethod, strProtocol, strToBeSend, strUID, strUrl;
// declare all the private functions
var defaultEvent_onreadystatechange, getXMLRequester, init, realEvent_onreadystatechange, uid;
// declare public variable
this.blnSendDefaultHeader=false;
this.readyState=0;
this.responseText="";
this.responseXML="";
this.status=-1;
// public event
this.onreadystatechange=defaultEvent_onreadystatechange;
// public method
this.attachEvent=function(eventHandle,functionHandle){
var eventHandle=String(eventHandle).toLowerCase();
switch(eventHandle){
case "onreadystatechange":
if(this.onreadystatechange!=defaultEvent_onreadystatechange){
this.onreadystatechange=defaultEvent_onreadystatechange;
aryOnPropertyChange_AttachedEvents=new Array();
}
aryOnPropertyChange_AttachedEvents.push(functionHandle);
return(true);
break;
default:
return("Not reallized yet.");
break;
}
}
this.deleteRequestHeader=function(strName){
delete aryRequestHeaders[strName];
}
this.detachEvent=function(eventHandle,functionHandle){
var eventHandle=String(eventHandle).toLowerCase();
switch(eventHandle){
case "onreadystatechange":
if(this.onreadystatechange!=defaultEvent_onreadystatechange){
this.onreadystatechange=defaultEvent_onreadystatechange;
aryOnPropertyChange_AttachedEvents=new Array();
return(true);
}
for(var i=0;i<aryOnPropertyChange_AttachedEvents.length;i++){
if(aryOnPropertyChange_AttachedEvents[i]==functionHandle){
aryOnPropertyChange_AttachedEvents.splice(i,1);
break;
}
}
return(true);
break;
default:
return("Not reallized yet.");
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){
var theURL;
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(var i in aryRequestHeaders){
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;
}
// private functions
function defaultEvent_onreadystatechange(){}
function getXMLRequester(){
var xmlhttp_request = false;
try{
if( window.ActiveXObject ){
for( var i = 5; i > -1; i-- ){
try{
if( i == 2 ){
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP" );
}else{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP." + i + ".0" );
}
break;
}catch(e){
xmlhttp_request = false;
}
}
}else if( window.XMLHttpRequest ){
xmlhttp_request = new XMLHttpRequest();
}
}catch(e){
xmlhttp_request = false;
}
return xmlhttp_request;
}
function init(){
// init private variable
aryArgu=new Array();
aryOnPropertyChange_AttachedEvents=new Array();
aryRequestHeaders=new Array();
blnAsyn=true;
objRequest=getXMLRequester();
objSelf=this;
objThat=this;
strMethod="GET";
strProtocol="unknown";
strResponseText="";
strToBeSend="";
strUID=strUID?strUID:uid();
strUrl="";
// init public variable
this.blnSendDefaultHeader=false;
// regist this object to window
window[strUID]=this;
}
function realEvent_onreadystatechange(){
objThat.flush();
if(objThat.onreadystatechange==defaultEvent_onreadystatechange){
for(var i=0;i<aryOnPropertyChange_AttachedEvents.length;i++){
try{
if(typeof(aryOnPropertyChange_AttachedEvents[i])=="function"){
aryOnPropertyChange_AttachedEvents[i].call(objThat);
}else if(typeof(aryOnPropertyChange_AttachedEvents[i])=="string"){
eval(aryOnPropertyChange_AttachedEvents[i]);
}
}catch(e){alert("004"+e.description)}
}
}else{
try{
if(typeof(objThat.onreadystatechange)=="function"){
objThat.onreadystatechange();
}else if(typeof(objThat.onreadystatechange)=="string"){
eval(objThat.onreadystatechange);
}
}catch(e){alert("005"+e.description)}
}
}
function uid(){
return("u"+(new Date()).getTime().toString(35)+parseInt(Math.random()*999999).toString(35));
}
// do init
this.init();
}
window.onload=init;
window.onresize=resizeWin;
window.onerror=cancelErr;
</script>
</head>
<body>
<input id="i1"><br>
<iframe id="f1"></iframe>
</body>
脚本宝典总结
以上是脚本宝典为你收集整理的超简陋浏览器全部内容,希望文章能够帮你解决超简陋浏览器所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。