&& /to_nextpage|loadnextpage/.test(String(wrap.className))) continue; var txt = la.textContent || ''; var same = true; try { same = !la.host || la.host === location.host; } catch (e) {} if (scrubText(txt).replace(/[\s  ]/g, '') === '') { if (la.parentNode) la.parentNode.removeChild(la); } else if (!same) { la.parentNode.replaceChild(document.createTextNode(scrubText(txt)), la); } } /* 广告删干净后只剩空白或标点的段落,整段去掉; 「点击下一页继续阅读」那几行带链接/按钮,不动。 */ var ps = box.getElementsByTagName('p'); for (i = ps.length - 1; i >= 0; i--) { var el = ps[i]; if (el.getElementsByTagName('a').length || el.getElementsByTagName('button').length) continue; t = (el.textContent || '').replace(/[\s  ]/g, ''); if (t === '' || !/[一-龥A-Za-z0-9]/.test(t)) { if (el.parentNode) el.parentNode.removeChild(el); } } } catch (e) {} cleaning = false; } function tick() { repaint(); cleanBox(); } /* 「翻页」这个勾选框是主题自带的,功能无效,直接从工具条上摘掉。 两种可能的结构都处理:,或 文字+ 并排。 */ function killPager() { var boxes = document.querySelectorAll('input[type=checkbox]'); for (var i = 0; i < boxes.length; i++) { var cb = boxes[i]; var lab = cb.closest ? cb.closest('label') : null; if (lab && lab.textContent.indexOf('翻页') >= 0) { lab.parentNode.removeChild(lab); return true; } var p = cb.previousSibling; while (p) { if (p.nodeType === 3) { if (p.nodeValue.indexOf('翻页') >= 0) { p.nodeValue = p.nodeValue.replace(/翻页/g, ''); cb.parentNode.removeChild(cb); return true; } if (p.nodeValue.replace(/\s/g, '') !== '') break; } else if (p.nodeType === 1) { if (p.tagName !== 'INPUT' && p.tagName !== 'SELECT' && p.textContent.indexOf('翻页') >= 0) { p.parentNode.removeChild(p); cb.parentNode.removeChild(cb); return true; } break; } p = p.previousSibling; } } return false; } function init() { killPager(); hookBgSelect(); hookFontSelect(); applyFont(); hookNight(); tick(); if (window.MutationObserver) { new MutationObserver(function () { cleanBox(); }).observe( document.getElementById('content') || document.documentElement, { subtree: true, childList: true } ); } setTimeout(function () { killPager(); hookBgSelect(); hookFontSelect(); applyFont(); hookNight(); tick(); }, 1200); setTimeout(function () { killPager(); hookFontSelect(); applyFont(); tick(); }, 3000); /* 一键收藏分享 */ var btn = document.getElementById('oneKeyShare'); var tip = document.getElementById('shareTip'); var siteurl = location.protocol + '//' + location.host + '/'; function flash(el) { if (!el) return; el.style.display = 'inline'; if (el._t) clearTimeout(el._t); el._t = setTimeout(function () { el.style.display = 'none'; }, 3000); } function fallbackCopy(text) { var ta = document.createElement('textarea'); ta.value = text; ta.setAttribute('readonly', ''); ta.style.position = 'fixed'; ta.style.left = '-9999px'; document.body.appendChild(ta); ta.select(); try { document.execCommand('copy'); } catch (e) {} document.body.removeChild(ta); } if (btn) { btn.onclick = function () { if (navigator.clipboard && navigator.clipboard.writeText) { navigator.clipboard.writeText(siteurl).then( function () { flash(tip); }, function () { fallbackCopy(siteurl); flash(tip); } ); } else { fallbackCopy(siteurl); flash(tip); } return false; }; } /* 加入书架 */ var shelfBtn = document.getElementById('addShelf'); var shelfTip = document.getElementById('shelfTip'); var shelfBox = document.getElementById('shelfWrap'); if (shelfBtn) { var inShelf = false; try { inShelf = !!(window.lastread && lastread.get(article_id)); } catch (e) {} if (inShelf) { if (shelfBox) shelfBox.style.display = 'none'; } else { shelfBtn.onclick = function () { try { if (window.lastread && typeof lastread.set === 'function') { lastread.set(article_id, chapter_id, articlename, chaptername, bookauthor, bookcatename, booksubid); } } catch (e) {} shelfBtn.style.display = 'none'; flash(shelfTip); return false; }; } } } if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); } else { init(); } })();