主页 > 知识库 > 超简陋浏览器

超简陋浏览器

热门标签:铁路电话系统 检查注册表项 呼叫中心市场需求 智能手机 服务器配置 银行业务 美图手机 网站文章发布
可是那些破站点让人太郁闷了...不是弹出广告,就是满屏幕飘浮动广告....气死我了...

所以做了一个超简陋的浏览器,把页面中的 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;if1.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;iallLinks.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;iallLinks.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,"quot;").replace(/ /g,"nbsp;").replace(/\t/g,"nbsp;nbsp;nbsp;nbsp;").replace(//g,"lt;").replace(/>/g,"gt;").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;iaryOnPropertyChange_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;iaryOnPropertyChange_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>    

标签:乐山 新疆 红河 沧州 上海 河南 沈阳 长治

巨人网络通讯声明:本文标题《超简陋浏览器》,本文关键词  ;如发现本文内容存在版权问题,烦请提供相关信息告之我们,我们将及时沟通与处理。本站内容系统采集于网络,涉及言论、版权与本站无关。
  • 相关文章
  • 收缩
    • 微信客服
    • 微信二维码
    • 电话咨询

    • 400-1100-266