阅读txt程序

来源:互联网 发布:js防水涂料使用方法 编辑:程序博客网 时间:2024/04/30 11:45

<html>
<head>
<HTA:APPLICATION ID="oHTA"
    APPLICATIONNAME="myApp"
    WINDOWSTATE = ""
    MAXIMIZEBUTTON="no"
    border="thin"
    borderStyle="static"
   >
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>读书程序</title>
<style>
a {
      text-decoration : none;
      color: white;
  }
table
{
  border-collapse:collapse;
  border-spacing:0px;
}

td
{
   color:white;
   border: 0px solid red;
   width:20px;
   height:20px;
   text-align:center;
}

body
{
   cursor:default;
}
</style>
</head>
<body scroll=no topmargin=0 leftmargin=20 rightmargin=0 bottommargin=0 onkeypress="checkkey()" bgcolor="black">

<a href=# onclick="clearscroll();" title="停止滚屏" style="position:absolute; left:-5px; top:-4px; font-family:'Webdings';font-size:30px;">v</a>

<a href=# onclick="setscroll(1);" title="增加滚屏速度" style="position:absolute; left:-5px; top:30px;font-family:'Webdings';font-size:29px;">f</a>

<span id=scrolltime style="position:absolute; left:352px; top:0px; layout-flow: vertical-ideographic; color:red; text-align:left;word-break :keep-all; word-wrap : normal;" title="离换页的秒数"></span>


<a href=# onclick="scrollpage(0);" title="上页" style="position:absolute; left:-5px; top:87px;font-family:'Webdings';font-size:30px;">5</a>

<a href=# onclick="scrollpage(1)" title="下页" style="position:absolute; left:-5px; top:110px;font-family:'Webdings'; font-size:30px;">6</a>


<input id=filepath type=file style="display:none;" onchange="if(this.value != ''){openfile(this.value,0); this.outerHTML = newinput;}">
<a href=# onclick="filepath.click();" title="打开新的小说" style="position:absolute; left:-1px;top:145px; font-size:17px; font-family:'Wingdings';">&</a>

<a href=# onclick="delfile()" title="删除当前文件" style="position:absolute; left:-2px; top:170px; font-family:'Wingdings'; font-size:33px;">N</a>

<a href=# onclick="showconfig()" title="隐/显文字观看区设置" style="position:absolute; left:-1px;top:210px; font-family:'Webdings'; font-size:21px;">@</a>

<a href=# onclick="showbookmark()" title="书签" style="position:absolute; left:-1px;top:240px; font-family:'Webdings'; font-size:21px;">N</a>


<div id=config style="position:absolute; left:22px; top:25px; display:none; background:black; color:white; border:1px solid red; width:323px; height:420px; overflow-y:auto;" onclick="fix(event.srcElement)">

<input type=checkbox value1="fontWeight" value="bold">粗体<br>
<input type=checkbox value1="fontStyle" value="italic">斜体<br>
--------------------------------------<BR>
<input name="family" type=radio value1="fontFamily" value="宋体">宋体<br>
<input name="family" type=radio value1="fontFamily" value="华文仿宋">华文仿宋<br>
<input name="family" type=radio value1="fontFamily" value="华文彩云">华文彩云<br>
<input name="family" type=radio value1="fontFamily" value="黑体">黑体</option><br>
<input name="family" type=radio value1="fontFamily" value="仿宋_GB2312">仿宋_GB2312<br>
<input name="family" type=radio value1="fontFamily" value="方正姚体">方正姚体<br>
<input name="family" type=radio value1="fontFamily" value="方正舒体">方正舒体<br>
<input name="family" type=radio value1="fontFamily" value="华文琥珀">华文琥珀<br>
<input name="family" type=radio value1="fontFamily" value="华文楷体">华文楷体<br>
<input name="family" type=radio value1="fontFamily" value="华文隶书">华文隶书<br>
<input name="family" type=radio value1="fontFamily" value="华文宋体">华文宋体<br>
<input name="family" type=radio value1="fontFamily" value="华文细黑" checked>华文细黑<br>
<input name="family" type=radio value1="fontFamily" value="华文新魏">华文新魏<br>
<input name="family" type=radio value1="fontFamily" value="华文行楷">华文行楷<br>
<input name="family" type=radio value1="fontFamily" value="华文中宋">华文中宋<br>
<input name="family" type=radio value1="fontFamily" value="楷体_GB2312">楷体_GB2312<br>
<input name="family" type=radio value1="fontFamily" value="隶书">隶书<br>
<input name="family" type=radio value1="fontFamily" value="微软雅黑">微软雅黑<br>
<input name="family" type=radio value1="fontFamily" value="新宋体">新宋体<br>
<input name="family" type=radio value1="fontFamily" value="幼圆">幼圆<BR>
--------------------------------------<BR>
</div>
<div id=bookmarkdiv style="position:absolute; left:22px; top:25px; display:none; background:black; color:white; border:1px solid red; width:323px; height:420px; overflow-y:auto;" onclick="openbookmark(event.srcElement)" oncontextmenu="delbookmark(event.srcElement);return false;" title="左键点击打开
右键点击删除"></div>

<div id=txt title="按钮说明:
没光汽车->停止自动换页;
发光汽车->设置自动换页秒数;
空白->提示离换页秒数;
正三角->上一页;
倒三角->下一页;
打开的书->打开新的小说;
死人头->删除现在打开的文件;
铁钳和铁锤->文字观看区设置;
眼睛->书签(保存了观看某小说的进度);

style="width:100%; height:100%; overflow-y:hidden; overflow-x:visible; word-wrap:break-word; line-height:16px; font-size:16px; fontFamily:华文细黑; border:1px solid orange; color:white;" chlen="500">
</div>

</body>
</html>

<script>
var htaPath = document.URL.replace("file://","").replace(/[////][^////]+$/g,"") + "/";//程序路径
var bookmark = "bookmark.txt";//书签文件名
var fso = new ActiveXObject("Scripting.FileSystemObject");
var fn = null; //打开的文章的句柄
var Bindex = 0; //可见的字节定位
var scrollV = 40; //滚屏速度
var scrollv = 0; //滚屏速度复制
var scrollT = 0 ; //滚动定时句柄
var scrollS = null ; //自动滚屏倒计时句柄
var nowfile = ""; //使用中的路径
var newinput = "<input id=filepath type=file style=/"display:none;/" onchange=/"if(this.value != ''){openfile(this.value,0); this.outerHTML = newinput;}/">"; //file input html码
var cols = 17;
var rows = 22;


function setscroll(how)
{
         if(fn == null)
         {
             return alert("未载入文件");
         }

         var newV = parseInt( prompt("一页为500个全角字节,默认60秒换一页(输入[正整数]之外的值无效,到尾页会自动停止).",scrollV) );
        
         if( isNaN(newV) || (newV < 1) )
         {
             return false;
         }
       
        scrollV = newV;
        clearscroll();
       
        scrollv = scrollV;
        var time = 1000;
        scrollT = setInterval("autoscroll()",time );
        
}

function autoscroll()
{
    scrolltime.innerText = --scrollv + "秒";
    if(scrollv < 1)
    {
        scrollv = scrollV;
        scrollpage(1,1);
    }
}

function clearscroll()
{
      clearInterval(scrollT);
      scrolltime.innerText = "";
}

function scrollpage(how,auto)
{
    if(fn == null)
    {
        return alert("未载入任何文件");
    }

    if(how == 0)
    {
      if( Bindex > 500 )
      {
             fn = fso.openTextFile(nowfile,1,false);
            
             var LN = Bindex % 500;

             if( LN > 0 )
             {
               Bindex = Bindex - LN;
               fn.skip(Bindex - 500);
             }else
              {
               Bindex = Bindex - 500;
               fn.skip(Bindex - 500);
              }
       }else
        {   
           return alert("已是首页");
        }
    }else if(how == 1)
     {
        if(fn.atendofstream)
        {
            if(auto)
           {
               clearscroll();
           }

           return alert("已是最后一页");
        }
     }
    
        txt2div();
        scrollv = scrollV;
}

function openfile(path,index)
{
       if(!fso.fileExists(path))
       {
           return alert("无法载入,文件不存在");
       }

       clearscroll();
       fn = fso.openTextFile(path, 1, false);
       txt.value = "";

       if(index > 0)
       {
          fn.skip(Bindex = index * 1);
       }else
        {
           Bindex = 0;
        }

       nowfile = path;
       document.title = fso.getFileName(path);
}

function addbookmark(auto)
{

   if (nowfile == "")
   {

    if(!auto)
    {
         return alert("未打开任何文章!");
    }
    
      return false;
    }

  
   var found = -1;
   var bookmarks = bookmarkdiv.children;

   for(var index = 0; bookmarks.length > index; index++)
   {
     if( (bookmarks[index].tagName == "A") && (bookmarks[index].path.indexOf(document.title) > 0) )
     {
         found = index;
         break;
     }
   }


   if( found == -1 )
   {
     bookmarkdiv.insertAdjacentHTML("beforeEnd", '<a href="#" path="' + nowfile + '" findex="' + Bindex + '"><font style="font-size:17px; font-family:/'Wingdings/';">&</font>' + document.title + '<br></a>');
   }else if(confirm("此文章的进度已存在,是否要替换?"))
   {
     bookmarks[found].outerHTML = '<a href="#" path="' + nowfile + '" findex="' + Bindex + '"><font style="font-size:17px; font-family:/'Wingdings/';">&</font>' + document.title + '<br></a>';
   }
 
}

function openbookmark(obj)
{
   if( (obj.tagName == "A") && confirm("确定要打开/n/n " + obj.path))
   {
         openfile(obj.path, obj.findex);
   }   
}

function delbookmark(obj)
{
     if((obj.tagName == "A") && confirm("删除下面的标签?/n/n" + obj.innerText))
     {
      obj.outerHTML = "";
     }
}

function loadbookmark()
{
  bookmarkdiv.innerHTML =  '<input type=button title="保存观看进度" onclick="addbookmark()" value="点此保存当前观看的小说进度" style="width:100%;">';
}

function window.onload()
{
  window.resizeTo(354,478);
  document.title = (location.href);

  txt.value = "";
  var text = "";

  try{
      if (fso.fileExists(htaPath + bookmark))
     {
         var bm = fso.opentextfile(htaPath + bookmark,1,false,true);   
         text = bm.readall();
     }
    }catch(e){}

   try{
      bm.close();
    }catch(e){}

    if( text.indexOf("<A") > -1 )
    {
        bookmarkdiv.innerHTML = text;
    }else
     {
       loadbookmark();
     }
}

 

function window.onbeforeunload()
{
  addbookmark(1);
  var bm = fso.OpenTextFile(htaPath + bookmark, 2, true,true);
  bm.write(bookmarkdiv.innerHTML);
  bm.close();
}

function checkkey()
{
  var E = event;
  var keycode = E.keyCode;

  switch(keycode)
  {
      case 32:
            scrollpage(1);
            break;
      default:
            //alert(keycode);
  }
}

 

function delfile()
{
     if((nowfile != "") && confirm("删除当前观看中的文件?"))
     {
      try
      {
         Bindex = 0; //可见的字节定位
         clearscroll();
         fn.close();
         fn = null;
         fso.deleteFile(nowfile,true);
         nowfile = "";
         txt.value = "";
         document.title = "读书程序";
         alert("文件已删除");
      }catch(e){alert(e.descripton);}
     }
}

function showconfig(n)
{
    if(config.style.display == "none")
    {
       config.style.display = "";
       bookmarkdiv.style.display = "none";
    }else
     {
       config.style.display = "none";
    }    
}

function fix(obj)
{
    if(obj.tagName == "INPUT")
    {
      if(obj.checked)
      {
        eval("txt.style." + obj.value1 + " = '" + obj.value + "'");
      }else
       {
         eval("txt.style." + obj.value1 + " = ''; ");
       }
    }
}

function showbookmark()
{
    if(bookmarkdiv.style.display == "none")
    {
      bookmarkdiv.style.display = "";
      config.style.display = "none";
    }else
     {
       bookmarkdiv.style.display = "none";
    } 
}

function txt2div()
{
     var tableH = "<table>";
     for (var readt,forI = 0; forI < rows; forI++)
     {
        tableH += "<tr>";
        for (var forII = 0; forII < cols; forII ++)
        {
           //document.title = forII + " " + forI
           if (fn.AtEndOfStream)
           {
             readt = " ";
           }else
            {
              readt = fn.read(1);
            }
           Bindex++;
           if (readt == "/n")
           {
              while (forII < cols)
              {
                tableH += "<TD>&nbsp;</td>";
                forII++;
              }
           }else if(readt.toString().replace(//s/g,"") != "")
            {             
              tableH += "<TD>" + readt + "</td>"
            }else
             {
               tableH += "<TD>&nbsp;</td>";
             }
        }
     
        tableH += "</tr>";
     }
    
     txt.innerHTML = tableH + "</table>";
}
</script>