// ==UserScript== // @name linovelib // @namespace https://github.com/IronKinoko/userscripts/tree/master/packages/linovelib // @version 1.4.5 // @license MIT // @description 优化 linovelib 阅读体验 // @author IronKinoko // @match https://www.linovelib.com/* // @match https://w.linovelib.com/* // @icon https://www.google.com/s2/favicons?domain=w.linovelib.com // @grant none // @noframes // @downloadURL none // ==/UserScript== (function () { 'use strict'; function isMobile() { const re = /iphone|ipad|ipod|android|webos|blackberry|windows phone/i; const ua = navigator.userAgent; return re.test(ua); } function normalizeKeyEvent(e) { const SPECIAL_KEY_EN = "`-=[]\\;',./~!@#$%^&*()_+{}|:\"<>?".split(""); const SPECIAL_KEY_ZH = "\xB7-=\u3010\u3011\u3001\uFF1B\u2018\uFF0C\u3002/\uFF5E\uFF01@#\xA5%\u2026&*\uFF08\uFF09\u2014+\u300C\u300D\uFF5C\uFF1A\u201C\u300A\u300B\uFF1F".split(""); let key = e.key; if (e.code === "Space") { key = "Space"; } if (/^[a-z]$/.test(key)) { key = key.toUpperCase(); } else if (SPECIAL_KEY_ZH.includes(key)) { key = SPECIAL_KEY_EN[SPECIAL_KEY_ZH.indexOf(key)]; } let keyArr = []; e.ctrlKey && keyArr.push("ctrl"); e.metaKey && keyArr.push("meta"); e.shiftKey && !SPECIAL_KEY_EN.includes(key) && keyArr.push("shift"); e.altKey && keyArr.push("alt"); if (!/Control|Meta|Shift|Alt/i.test(key)) keyArr.push(key); keyArr = [...new Set(keyArr)]; return keyArr.join("+"); } function keybind(keys, keydown, keyup) { const isMac = /macintosh|mac os x/i.test(navigator.userAgent); keys = keys.filter((key) => !key.includes(isMac ? "ctrl" : "meta")); function createProcess(callback) { return function(e) { var _a; if (((_a = document.activeElement) == null ? void 0 : _a.tagName) === "INPUT") return; const normalizedKey = normalizeKeyEvent(e).toLowerCase(); for (const key of keys) { if (key.toLowerCase() === normalizedKey) callback(e, key); } }; } window.addEventListener("keydown", createProcess(keydown)); if (keyup) window.addEventListener("keyup", createProcess(keyup)); } function matcher(source, regexp) { if (typeof regexp === "string") return source.includes(regexp); return !!source.match(regexp); } function router(config) { const opts = { domain: "", routes: [] }; if ("routes" in config) { opts.domain = config.domain; opts.routes = config.routes; } else { opts.routes = Array.isArray(config) ? config : [config]; } if (opts.domain) { const domains = Array.isArray(opts.domain) ? opts.domain : [opts.domain]; const match = domains.some( (domain) => matcher(window.location.origin, domain) ); if (!match) return; } const pathSource = window.location.pathname + window.location.search + window.location.hash; if (typeof opts.routes === "function") { opts.routes(); return; } const routes = Array.isArray(opts.routes) ? opts.routes : [opts.routes]; routes.forEach((route) => { let match = true; if (route.path) { match = matcher(pathSource, route.path); } if (route.pathname) { match = matcher(window.location.pathname, route.pathname); } if (route.search) { match = matcher(window.location.search, route.search); } if (route.hash) { match = matcher(window.location.hash, route.hash); } if (match) route.run(); }); } async function main$1() { router([{ pathname: /novel\/\d+\/catalog/, run: injectDownloadSection }]); if (!window.ReadTools) return; resetPageEvent(); if (isMobile()) injectMovePageEvent(); else injectShortcuts(); } function injectDownloadSection() { const bookId = window.location.pathname.match(/\d+/)[0]; document.querySelectorAll("#volumes .chapter-bar").forEach((node, idx) => { const api = `https://www.zhidianbao.cn:8443/qs_xq_epub/api/catalog/${bookId}/${idx}/sync`; node.innerHTML = ` ${node.textContent}
.*?)";.*nextpage="(?.*?)";') ); if (!(res == null ? void 0 : res.groups)) return; const { pre, next } = res.groups; keybind( ["w", "s", "a", "d"], (e, key) => { switch (key) { case "w": case "s": const direction = key === "w" ? -1 : 1; if (e.repeat) scroll.start(direction * 15); else window.scrollBy({ behavior: "smooth", top: direction * 200 }); break; case "a": case "d": window.location.pathname = key === "a" ? pre : next; break; } }, (e, key) => { switch (key) { case "w": case "s": scroll.stop(); break; } } ); } function injectDownload() { const bookId = window.location.pathname.split("/").pop().split(".").shift(); const dom = document.querySelector(".fr.link-group"); const a = document.createElement("a"); dom == null ? void 0 : dom.prepend(a); a.outerHTML = `Epub\u4E0B\u8F7D`; } const scroll = (() => { let handle; function stop() { if (!handle) return; cancelAnimationFrame(handle); handle = void 0; } function start(step) { if (handle) return; function animate() { handle = requestAnimationFrame(animate); window.scrollBy({ top: step }); } handle = requestAnimationFrame(animate); } return { start, stop }; })(); var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n div {\n position: absolute;\n pointer-events: none;\n left: 0;\n right: 0;\n bottom: 0;\n top: 0;\n}\n.k-wrapper #volumes .chapter-bar .progress > div {\n background-color: rgba(255, 57, 84, 0.1);\n transition: all 0.2s linear;\n}"; n(css,{}); document.body.classList.add("k-wrapper"); if (window.location.host.includes("www.")) { main(); } else main$1(); })();