ute('data-szwfont')) return; s.setAttribute('data-szwfont', '1'); s.onchange = null; while (s.firstChild) s.removeChild(s.firstChild); var lab = document.createElement('option'); lab.value = ''; lab.text = '字体'; s.appendChild(lab); var now = ls('szw_font') || ''; for (var k = 0; k < FONTS.length; k++) { var op = document.createElement('option'); op.value = FONTS[k].v; op.text = FONTS[k].t; if (FONTS[k].v === now && now !== '') op.selected = true; s.appendChild(op); } (function (sel) { sel.onchange = function () { ls('szw_font', sel.value); applyFont(); }; })(s); return; } } function applyFont() { var f = ls('szw_font'); var c = document.getElementById('content'); if (c) c.style.fontFamily = f || ''; } /* 接管「夜间」勾选框 */ function hookNight() { var boxes = document.querySelectorAll('.con_top input[type=checkbox], #wrapper input[type=checkbox]'); if (!boxes.length) return; var nb = boxes[boxes.length - 1]; /* 最后一个就是「夜间」 */ if (nb.getAttribute('data-szw')) return; nb.setAttribute('data-szw', '1'); nb.id = nb.id || 'szwNight'; nb.checked = isNight(); nb.onclick = function () { ls(NTKEY, nb.checked ? '1' : '0'); repaint(); }; } /* 清掉采集残留的空书名括号,以及源站塞在正文里的推广语 */ var ADS = [ /(?:%[0-9a-fA-F]{2}){6,}/g, /天才一秒记住[^。!?\n]{0,60}[。!?]?/g, /(一秒记住|记住本站|请记住本站|本站网址|最新章节请到|手机阅读请访问|首发地址|请收藏本站|域名请记住|无弹窗免费阅读)[^。!?\n]{0,60}[。!?]?/g, /【[^】]{0,40}(小说网|小说站|书屋|文学网|中文网|阅读网|书院|txt)[^】]{0,40}】/g, /[((]\s*[A-Za-z0-9][A-Za-z0-9\-]{1,30}\.(com|net|org|cc|info|xyz|top|vip|cn|me|la|tv)[^))]{0,20}[))]/gi, /[A-Za-z0-9][A-Za-z0-9\-]{2,30}\.(com|net|org|cc|info|xyz|top|vip)(\.cn)?/gi ]; var cleaning = false; function cleanBox() { var box = document.getElementById('content'); if (!box || cleaning) return; var h = box.innerHTML, n = h; n = n.replace(/[((]\s*《\s*》\s*[))]/g, ''); for (var i = 0; i < ADS.length; i++) n = n.replace(ADS[i], ''); /* 广告删干净后可能剩下空段落,一并去掉 */ n = n.replace(/

(\s| )*<\/p>/gi, ''); if (n !== h) { cleaning = true; box.innerHTML = n; 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(); } })();