NOTICE: By continued use of this site you understand and agree to the binding Terms of Service and Privacy Policy.
// ==UserScript== // @name 网易阅读打印 // @namespace 163 // @include http://yuedu.163.com/book_reader/* // @version 1 // @grant none // ==/UserScript== //循环次数 window.loop = 0; //打印内容 window.el = ''; //文档长度 window.le = 0; //延迟时间,请根据网速和机器情况测试后选择一个合适的值,秒 window.delay = 1000; window.start = function() { var delay = prompt("请确保在页面内容已加载完成后继续\n翻页时间,确保翻页加载可在该时间内完成,单位ms", 1000); console.log(delay); if (isNaN(delay) || delay <= 0) { alert("输入无效,退出"); return false; } else { window.delay = delay; } var page = prompt("请输入你要打印的页数,0为全部", 0); if (page == 0) { begin(); } else if (!isNaN(page)) { beginParam(page); } else { alert("输入无效,退出"); return false; } } //打印 window.printContent = function(z) { //移除文件头 document.getElementsByTagName('head')[0].innerHTML = "<style>p {font-size: 18px;text-align: justify;line-height:40px;margin:0 10px 0 10px;text-indent:30px;} </style>"; document.body.innerHTML = z; window.print(); } //取页面内容 window.getEl = function() { if (window.loop <= 1) { setTimeout(printContent(el), delay); } else { document.getElementsByClassName("next-turn J_NextTurn")[0].click(); //检测页面是否有已到最后一页的提示 if (document.getElementsByClassName("popo-private popo-black").length != 0) { setTimeout(printContent(el), delay); } else { setTimeout(getDoc, delay); window.loop = window.loop - 1; } } } //网易会一次性取好几页内容,因此判断一下长度是否变化来决定是否进入了下一页 window.getDoc = function() { tmpEl = document.getElementsByClassName("ne-content J_NEContent")[0].innerHTML; if (tmpEl.length != le) { el = el + '<div>' + tmpEl + '</div>'; le = tmpEl.length; } setTimeout(getEl, delay); } //启动入口 window.begin = function() { window.loop = 9999; getDoc(); } window.beginParam = function(x) { window.loop = x; getDoc(); } setTimeout(start, 5000);