现在的位置: 首页 > 综合 > 正文

使用hta在本地注入远程网页进行操作,解决hta不共享ie session和某些权限问题

2013年09月09日 ⁄ 综合 ⁄ 共 13022字 ⁄ 字号 评论关闭

提供思路;可以方便把编辑好的功能直接一键注入远程页面.

 

 

 

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>方便注入操作代码到远程网页程序</title>
</head>
<body>

窗口名字:<INPUT id=winn size=10 value="win" onchange="window.win = null; showText('网页将会新开窗口.');">(win窗口对象名,如已存在此窗口,将替换该窗口网址.)<BR>
网参连结:<INPUT id=wvs size=10 value="?">(网址连结参数串的字符.如?)<BR>
参参连结:<INPUT id=vvs size=10 value="&">(参数连结参数的字符.如&)<BR>
参值连结:<INPUT id=vas size=10 value="=">(参数连结参数值的字符.如=)<BR>
       
        <!--  //注意参数id总是varId,name放的是传给服务器的id//-->
x_____id:<INPUT id=varId value=0db1 size=10 sn="x_id"> <BR>
item__id:<INPUT id=varId size=35 sn="item_id" value="0a2f26d13eddf8f142d64cc71bf3abbc">
 <BR>sku___id:<INPUT id=varId size=10 sn="sku_id" value=>
 <BR>目标价格:<INPUT id=varId value=1.00 size=10 sn="mbjg" value="1.00">
<BR>收货人名:<INPUT id=varId size=10 sn="_fma.b._0.de" value="林伟军">
 <BR>收货地址:<INPUT id=varId size=50 sn="_fma.b._0.d" value="中山街706号">
<BR>手机号码:<INPUT id=varId size=13 sn="_fma.b._0.deli" value="13005609114">
 <BR>邮政编码:<INPUT id=varId size=10 sn="_fma.b._0.po" value=515000>
 <BR>我的留言:<INPUT id=varId value=请发申通快递或者圆通或者EMS都行,谢谢! size=50 sn="_fma.b._0.w">
<BR>运送方式:<SELECT id=varId sn="_fma.b._0.s">
 <OPTION selected value=4>模板快递</OPTION>
 <OPTION value=0>包邮</OPTION>
<OPTION value=2>普通快递</OPTION>
<OPTION value=1>平邮</OPTION>
<OPTION value=7 selected>EMS</OPTION>
</SELECT>
       <!-- //参数结束//-->
       
<BR><INPUT id=joinVarB onclick=joinVar(); value=连结参数 type=button style="width:10%;" title="连结后的字符串放到buyUrl.vars中;">        
<INPUT id=buyUrl name=buyUrl value="http://ebay.com" vars="" style="width:65%;" title="输入网址">
 <INPUT type=button value="创建win窗口/更换网址" style="width:20%;" onclick="createW();" title="使用此网址+参数串在新窗口打开;如果不需要参数串,可以清空后再打开.">
 <BR>
 <INPUT style="BORDER-BOTTOM: 0px; BORDER-LEFT: 0px; BORDER-TOP: 0px; BORDER-RIGHT: 0px;width:70px;" id=nt value=00:00:00 type=button name=nt >
抢拍时间:<INPUT id=hh maxLength=2 size=1 name=hh style="border:0px;">时
<INPUT id=mm maxLength=2 size=1 name=mm style="border:0px;">分
<INPUT id=ss maxLength=2 size=1 name=ss style="border:0px;">秒
<INPUT id=ss2 maxLength=3 size=2 name=ss2 style="border:0px;">毫秒<BR>
       
 <input type=button value=载入js onclick="eval(js.value);showText('所有涵数载入成功,你可以使用所有功能了');">
<INPUT onclick=insertWeb(); value=注入远程页面 type=button>
 <INPUT id=ksqp onclick=Sjsjtosubmit(); value=不停抢拍 type=button name=ksqp>
<INPUT onclick='$e("msg").innerHTML = "";' value=清空消息 type=button>
<a href="#0" onclick="this.children[0].click();">
消息滚屏<INPUT id=autoroll type=checkbox checked=true name=autoroll></a>
<a href="#0" onclick="this.children[0].click();">
自动拍下<INPUT id=autopai type=checkbox checked=true></a>
<BR><DIV id=msg style="border:1px solid black;width:100%;height:350px; overflow-y:auto; overflow-x:hidden; word-wrap :break-word;" ></DIV>
<textarea style="width:100%;height:50px;word-break:keep-all;overflow:scroll;" onkeypress="if (event.keyCode == 10) {eval(this.value)}"></textarea>
<div id=formD style="width:100%;height:100px;"></div>

 

<textarea id=js style="display:none;">

window.errFun = function(sMessage,sUrl,sLine)
{
   var str = "";

    str += " 错误信息:" + sMessage + "<br>";

    str += " 错误行数:" + sLine + "<br>";

    str += "<=========调用堆栈=========><br>";

    var func = window.onerror.caller;

    var index = 0;

    while(func!=null){

       str += "第" + index + "个函数:" + func.toString().split("{")[0] + "<br>";

       str += "第" + index + "个函数:参数表:"

       for (var i=0;i<func.arguments.length;i++){

           str += func.arguments[i] + ",";

       }

       str += "<BR>===================<br>";

       func = func.caller;

       index++;

    }

    showText(str);
   
   return true;
}

window.showNt=function ()
{//现在时间
  var d=new Date();
  $e('nt').value=d.getHours() + ":" + d.getMinutes() + ":" + d.getSeconds();
}

window.showText=function(text)
{ //text:传入的字符串;   
    $e("msg").insertAdjacentHTML("beforeEnd", new Date().toLocaleString() + " " + text + '<hr width=100%>');
    if ($e("autoroll").checked) $e("msg").scrollTop = $e("msg").scrollHeight;
    //$e("msg").insertAdjacentHTML("afterBegin", text + '<hr width=100%>');
    //$e("msg").scrollTop = 0; 
}

window.openUrl = function (url, fun)
{
   clearTimeout(window.winer);
  
   if (url != "")
    {      
        try
        {
           window.win.document;
           window.win.location = url;
           showText("替换win对象网址.");
        }catch(e)
       {
          showText("win对象不存在,创建.");
          window.win = open(url, $e("winn").value);
       }
      
       if (window.win == null)
       {
          showText("创建窗口失败,是否浏览器阻止弹出窗口?请允许本网页弹窗.");
          return 0;
       }
      
       try
       {
         showText("新窗口网页域名:" + window.win.location.host);
       }catch(e)
        {
         showText("注意:获取新窗口域名失败,动作中止!<BR>"
             +"可能新窗口网页域名[" + getHost(url) + "]跟本页面域名["+ location.host + "]不同,"
             +"如果在本页面(非hta)获取新窗口(不同域名)中的内容时会因为无权限禁止访问."
             +"如果服务器返回页面转向到相同域名时,还是可以访问的.");
         return 0;
        }
       
       showText("打开网址:" + url + "<BR>请不要进行其它操作....<BR>正在载入网页中,请等待载入完成...");      
       url = "";
    }else if (window.win.document.readyState == 'complete')
   {
      //alert(fun);
      eval(fun);
      showText("网页载入完成");
      return 0;
   }
  
  window.winer = setTimeout("openUrl('','" + fun + "')",1000);
}

window.getHost = function(url)
{
    showText("获取域名(只支持国际域名解析,即http(s)://英文或小数点或数字或-等字符组成;");
    if ( (url == undefined) || (typeof(url) != "string") || (! /^ *https?/:////([.a-z0-9/-]*)/gi.test(url)))return "";
    else return RegExp.$1;   
}

 window.insertWeb=function()
{
    showText("建议网页载入完成再进行此项操作!"
          + "<BR>且保证你注入的网址跟你要操作的必要一样,否则将会出现权限问题拒绝访问."
          + "<br>如你要操作的网址是http://www.google.com/ss.htm,"
          + "那么你必要打开的win对象的网址前面是http://www.google.com/....");
   
   if ((window.win == undefined) || (window.win.closed))
   {
      return showText("远程网页未打开或被关闭了.请重新打开.");
   }else
    {
      try
      {
       window.win.document.body.innerHTML = document.body.outerHTML;
       showText("写入远程页面成功,请切换到远程页面查看.");
      }catch(e)
       {
         showText("注入出错!请关闭远程窗口并重新创建后再试.!可能是xmlHttp异常导致.");
       }
    }
}

 window.createW=function()
{
  openUrl($e("buyUrl").value + $e("buyUrl").vars,'insertWeb();');
}

 window.$wfe=function(thef, thee)
{
   if (typeof(thee) == "undefined") return document.getElementById(thef);
   return document.getElementById(thef).elements[thee];
}

 window.$e=function(thid)
{
   return document.getElementById(thid);
}

 window.istime=function(num)
{
  if (isNaN(num)) return false;
  if (num < 0) return false;
  return ture;
}

 window.joinVar=function()
{//连结参数
 if ($e("joinVarB").value == "连结参数")
 {
  $e("joinVarB").value =  "清空参数"; 
  $e("buyUrl").vars = $e("wvs").value;
  var vars = document.getElementsByName("varId");
 
  for (var forI = 0; forI < vars.length; forI++)
  {
     if (forI == 0)
     {
        $e("buyUrl").vars += vars[forI].sn + $e("vas").value + (vars[forI].value);
     }else
     {
        $e("buyUrl").vars += $e("vvs").value + vars[forI].sn + $e("vas").value + (vars[forI].value);
     }
  }
 
  showText("参数连结如下<BR>" + $e("buyUrl").vars);
 }else
  {
     $e("buyUrl").vars = "";
     $e("joinVarB").value =  "连结参数";  
     showText("参数串已被清空"); 
  }
}

 window.isLogin=function()
{
  try
  {
    return (window.win.document.body.innerText.indexOf("标准登录") < 0);
  }catch (e)
   {
      showText("无法检测是否登录,请检查打开的网页是否正常.");
      return false;
   }
}

 window.Sjsjtosubmit=function()
{//不停去抢拍
 
  if ($e("ksqp").value == "不停抢拍")
  {
      showText("注意:此项操作最好在注入后的页面操作,因为hta在登录后一换页面登录信息就丢失,=同于没登录,"
              +"造成xmlhttp获取xx页面时被服务器转向到yy页面时返回空白信息.");
      if ($e("buyUrl").vars == "") showText("注意:参数串是空的.");
      if ($e("buyUrl").value.length < 10) return showText("请输入网址,一般网址是不能少于10个字符,如http://x.x.");
      $e("ksqp").value = "停止抢拍";
      sendRequestGet();
  }else
   {
     $e("ksqp").value = "不停抢拍";
     xmlAbor();
   }
 
}

 window.sendRequestGet=function()
{
       window.xmlHttp.onreadystatechange=getStateChange;
       /*
       if ($e("buyUrl").vars != "")      
          url  += "&t=" + Math.random();
       var url = $e('buyUrl').value + $e('buyUrl').vars + "&t=" + Math.random();
      
      
       if (getHost(url) != location.host)
       {
          showText("注意,xmlhttp读取域名[" + getHost(url) + "]跟本页域名["
            + location.host + "]不同,非hta页面是禁止跨域读取,注意操作!");
          return false;
       }
       showText("开始使用xmlhttp获取表单...网址是:<BR>" + url);
       */
         window.xmlHttp.open("get", $e('buyUrl').value + $e('buyUrl').vars + "&t=" + Math.random(), true);
         //showText("get成功");
        // window.xmlHttp.setRequestHeader("Content-Type", "text/html");
         //window.xmlHttp.setRequestHeader("Accept-Charset","gb2312");
         //window.xmlHttp.setRequestHeader("Accept-Language","zh-cn");
         window.xmlHttp.send();
         //showText("send完成");
}

window.xmlAbor=function()
{     
    clearTimeout(window.geter);
    clearInterval(window.clicker);
    window.xmlHttp.abort();
    //showText("xmlHttp被中止");
}

 window.getStateChange=function()
{
  //if ( ($e("ksqp").value != "停止抢拍") ) return xmlAbor();
 
  switch(window.xmlHttp.readyState)
  {// 4 = "loaded"
  /*需要时取消
    case 0:
        showText("xmlHttp对象对象已存在");
        break;
    case 1:
        showText("xmlHttp对象初始化");
        break;
    case 2:
        showText("xmlHttp对象已发送数据");
        break;
    case 3:
        showText("xmlHttp对象数据传送中");
        break;
    */
    case 4:
       //showText("xmlHttp对象数据接收完毕");
      
       switch (window.xmlHttp.status)
       {
          case 200:
              //showText (window.xmlHttp.getAllResponseHeaders());//需要查看收到的头时打开
             //var gform = /<form.*"mainform"[/s/S]*<//form>/i.exec(window.xmlHttp.responseText);
            
             try
             {
                $e("formD").innerHTML = '<form name="mainform" class="trade:confirmInfoForm" id="mainform"  action="http://ebay.com" method="post" target=_blank>'
                          + window.xmlHttp.responseText.split('<form name="mainform" class="trade:confirmInfoForm" id="mainform"  action="http://ebay.com" method="post">')[1].split('</form>')[0] + "</form>";
                         
                     
                      window.clicker = setInterval(function(){
                                     try {
                                       document.getElementById("performSubmit").click();
                                       clearInterval(window.clicker);
                                       Sjsjtosubmit();
                                     }catch(e){}
                                       }, 1);
             }catch(e)
              {             
                xmlAbor();
                window.geter = setTimeout("sendRequestGet();",1);
              }
            
            
             /*
              var gform = window.xmlHttp.responseText.indexOf('name="mainform"');//查看源文件中唯一的字符.断定
              if (gform > -1)
              {//出现form的唯一字符                  
                     //showText("出现了form");
                      //showText("生成fun<BR>写入读取内容...");
                       window.times = 0;
                      if ($e("autopai").checked)
                      window.clicker = setInterval(function(){
                                     try {
                                     document.title = window.times++;
                                       document.getElementById("performSubmit").click();
                                       document.title = window.times++;
                                       clearInterval(window.clicker);
                                     }catch(e){document.status = window.times++;}
                                       }, 1);  
                      $e("formD").innerHTML = window.xmlHttp.responseText;
                      Sjsjtosubmit();
              }else
              {
                //showText("xmlHttp返回无符合.");              
                xmlAbor();
                window.geter = setTimeout("sendRequestGet();",1);
               }
              
               */
              break;
          case 0:
              showText("页面可能存在转向...获取失败!请检查页面返回的地址是不是跟提交时一样.如未登录时,会被转向到登录页面.");
              break;
          default:
              showText("xmlHttp.status: "
                    + window.xmlHttp.status
                    + "["+window.xmlHttp.statusText + "]"
                    + "<BR>" + window.xmlHttp.responseText
                    );
             //Sjsjtosubmit();
       }
        break;
   }

}

window.getXmlHttp=function()
{
  if (window.XMLHttpRequest)
  {// code for all new browsers
     window.xmlHttp=new XMLHttpRequest();
  }else if (window.ActiveXObject)
   {// code for IE5 and IE6
     window.xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
  
  if (window.xmlHttp == null)
  { 
     showText("你浏览器不支持xmlhttp,创建失败.");
     return false;
  }
 
  showText("xmlHttp创建成功.");
}

window.sendBuy2 = function ()
{     
   try
   {
           window.swin.document.documentElement.outerHTML;
   }catch(e)
    {
          showText("swin对象不存在,创建.");
          window.swin = open("http://http://ebay.com", "swin");
    }
   
   if (window.swin == null)
   {
     showText("创建窗口失败,是否浏览器阻止弹出窗口?请允许本网页弹窗.");
     return 0;
   }
    
   var temFun = '<script' + '>/n'
              + 'times = 1000;setInterval(/'try {if (document.getElementById("checkCode") || (times-- == 0))try{opener.sendRequestGet();}catch(e){document.title="重新执行读取出错.";};else document.getElementById("performSubmit").click(),setTimeout("opener.sendRequestGet();",5000);}catch(e){document.title="执行click出错.";}/', 10);'
              + '</script' + '>/n';
   showText("生成fun<BR>写入读取内容...");   
  window.swin.document.body.innerHTML = temFun + window.xmlHttp.responseText;
   showText("写入完成.");
}

//-------------
   $e("msg").innerHTML = "";
   getXmlHttp();
   $e("buyUrl").value = "http://ebay.com";
   $e("winn").value = "win";
   $e("joinVarB").value =  "连结参数";  
   joinVar();
   window.onerror = window.errFun;
   setInterval('showNt();',1000);
   showText("启动全局函数完成.");
//启动全局
</textarea>

</body>
</html>

抱歉!评论已关闭.