enhance manhuagui
// ==UserScript== // @name manhuagui // @namespace https://github.com/IronKinoko/userscripts/tree/master/packages/manhuagui // @version 1.0.7 // @license MIT // @description enhance manhuagui // @author IronKinoko // @match https://www.manhuagui.com/comic/* // @icon https://www.google.com/s2/favicons?domain=manhuagui.com // @grant none // @noframes // @require https://unpkg.com/[email protected]/dist/jquery.min.js // ==/UserScript== (function() { //#region ../shared/src/utils/sleep.ts function sleep(ms) { if (!ms) return new Promise((resolve) => { requestAnimationFrame(resolve); }); return new Promise((resolve) => { setTimeout(resolve, ms); }); } //#endregion //#region ../shared/src/utils/wait.ts async function wait(selector) { let bool = await selector(); while (!bool) { await sleep(); bool = await selector(); } } //#endregion //#region ../shared/src/utils/is.ts function isMobile() { const re = /iphone|ipad|ipod|android|webos|blackberry|windows phone/i; const ua = navigator.userAgent; return re.test(ua); } //#endregion //#region ../shared/src/utils/dom.ts async function waitDOM(selector, root = document) { await wait(() => !!root.querySelector(selector)); return root.querySelector(selector); } //#endregion //#region \0virtual:bocchi-style-runtime function injectStyle(css) { if (typeof document === "undefined") return; const style = document.createElement("style"); style.setAttribute("data-bocchi", ""); document.head.append(style); style.textContent = css; } //#endregion //#region src/index.scss injectStyle(".k-custom-btn.k-custom-btn {\n text-indent: 0;\n background: #b5b5b5;\n color: white;\n line-height: 40px;\n text-align: center;\n text-decoration: none;\n}\n.k-custom-btn.k-custom-btn:hover {\n background: #c00f20;\n}\n\n.backToTop {\n height: auto !important;\n}\n\n.tbCenter {\n border: none !important;\n background: none !important;\n}\n\n[data-tag=mangaFile] {\n width: 980px !important;\n}\n\n.big-h5-btn {\n width: calc(100% - 72px);\n display: block;\n height: 100px;\n background-color: #c00f20;\n color: white;\n font-size: 36px;\n margin: 36px auto;\n outline: 0;\n border: #c00f20;\n}\n\n.next-part-btn-fixed {\n position: fixed;\n right: 0;\n top: 25vh;\n font-size: 4.27vw;\n background: white;\n padding: 2.13vw;\n writing-mode: vertical-lr;\n box-shadow: rgba(0, 0, 0, 0.2) -0.27vw 0.27vw 2.67vw 0vw;\n transition: all 0.2s ease;\n transform: translateX(0);\n border-radius: 1.07vw 0 0 1.07vw;\n opacity: 1;\n}\n.next-part-btn-fixed.hide {\n opacity: 0;\n pointer-events: none;\n transform: translateX(100%);\n}"); //#endregion //#region src/index.ts (async () => { document.oncontextmenu = null; createNextBtn(); createFullScreen(); if (isMobile()) createNextBtnInH5(); })(); async function createNextBtn() { const dom = await waitDOM(".backToTop"); const a = document.createElement("a"); a.innerHTML = "NEXT"; a.className = "k-custom-btn"; a.id = "show-next"; a.href = "javascript:;"; a.onclick = window.SMH.nextC; dom.append(a); } async function createFullScreen() { const dom = await waitDOM(".backToTop"); const a = document.createElement("a"); a.innerHTML = "FULL"; a.className = "k-custom-btn"; a.id = "full-btn"; a.href = "javascript:;"; a.onclick = () => { if (document.fullscreenElement) { document.exitFullscreen(); a.innerHTML = "FULL"; } else { document.documentElement.requestFullscreen(); a.innerHTML = "EXIT"; } }; dom.append(a); document.addEventListener("keypress", (e) => { if (document.activeElement && /textarea|input|select/i.test(document.activeElement.tagName)) return; if (e.key === "f") a.click(); }); } async function createNextBtnInH5() { const $pagination = await waitDOM("#pagination"); $pagination.innerHTML = ""; const btn = document.createElement("button"); btn.className = "big-h5-btn"; btn.textContent = "下一章"; btn.onclick = () => window.SMH.nextC(); $pagination.replaceWith(btn); } //#endregion })();