【摸yu】看看闲书用

    科技2025-04-21  9

    js代码,贴到console里用,也就看看novel,页数按'章'拆分。

     

    var novelArr=[]; function insert(eid) { if(!eid){eid='body';} $('body').append('<div id="con-div" style="position:fixed;top:90%;left:80%;z-index:1000;opacity: 0.5;font-size: 13px;"><div>' +' <input type="file" name="file" multiple id="fileId" style="width: 85px" />' +'<button name="btn" id="btnId" onclick="return addWord()">提交</button><button name="btn" onclick="del()">刪除</button>' +'</div>' +'<input id="jump" value="0" style="width: 50px"/><button type="button" onclick="jumppage(this)">jump</button>' +'<button type="button" num="0" onclick="nextpage(this)">next</button></div>'); $(eid).append('<div style="position: fixed;top:20%;height:90px;width:300px;overflow:scroll;font-size:13px;opacity: 0.4;z-index:999999" id="novel"></div>'); $(eid).append(" <style>::-webkit-scrollbar { width: 0 !important }</style>"); //获取元素 var dv = document.getElementById('novel'); var x = 0; var y = 0; var l = 0; var t = 0; var isDown = false; //鼠标按下事件 dv.onmousedown = function(e) { //获取x坐标和y坐标 x = e.clientX; y = e.clientY; //获取左部和顶部的偏移量 l = dv.offsetLeft; t = dv.offsetTop; //开关打开 isDown = true; //设置样式 dv.style.cursor = 'move'; } //鼠标移动 window.onmousemove = function(e) { if (isDown == false) { return; } //获取x和y var nx = e.clientX; var ny = e.clientY; //计算移动后的左偏移量和顶部的偏移量 var nl = nx - (x - l); var nt = ny - (y - t); dv.style.left = nl + 'px'; dv.style.top = nt + 'px'; } //鼠标抬起事件 dv.onmouseup = function() { //开关关闭 isDown = false; dv.style.cursor = 'default'; } } function addWord(){ var objFile = document.getElementById("fileId"); if(objFile.value == "") { alert("txt不能空") return false; } var files = $('#fileId').prop('files'); //获取到文件列表 console.log(files.length); if(files.length == 0 || files.length > 1) { alert('请选择一个文件'); return false; } else { for(var i = 0; f = files[i]; i++) { var reader = new FileReader(); //新建一个FileReader reader.readAsText(files[i], "UTF-8"); //读取文件 reader.onload = function(evt) { //读取完文件之后会回来这里 var fileString = evt.target.result; // 读取文件内容 novelArr=fileString.split(/章/g); $("#novel").html(novelArr[0]); /* var intervel=setInterval(function(){ //定时 document.getElementById('novel').scrollTop+=10; },1000) */ } } return false; } } function jumppage(e){ $("#novel").html(novelArr[Number($(e).prev().val())]) $(e).next().attr("num",Number($(e).prev().val())); document.getElementById('novel').scrollTop=0 } function nextpage(e){ var cur=Number($(e).attr("num")); $("#novel").html(novelArr[cur+1]); $(e).attr("num",cur+1); $(e).prev().prev().val(cur+1); document.getElementById('novel').scrollTop=0 } function del() { $("#novel").remove(); $("#con-div").remove(); } insert();
    Processed: 0.008, SQL: 8