Deqi Prefech

得奇小说网,看单个章节免翻页

// ==UserScript==
// @name         Deqi Prefech
// @namespace    https://greasyfork.runtimutd.eu.org/zh-CN/users/14997-lrh3321
// @version      2025-06-06
// @description  得奇小说网,看单个章节免翻页
// @author       LRH3321
// @license      MIT
// @match        https://www.deqixs.com/xiaoshuo/*/*.html
// @match        https://www.deqixs.com/xiaoshuo/*/
// @icon         https://www.google.com/s2/favicons?sz=64&domain=deqixs.com
// @grant        none
// @run-at       document-end
// ==/UserScript==
(function () {
    'use strict';
    function handleBookPage() {
        const itemtxt = document.querySelector('.itemtxt');
        const title = itemtxt.querySelector('h1>a').textContent;
        const latestChapter = itemtxt.querySelector('ul>li>a').textContent;
        document.title = `${title} - ${latestChapter}`;
        setTimeout(() => {
            location.reload();
        }, 600000);
    }
    function handleChaperPage() {
        const container = document.querySelector('div.container');
        if (location.pathname.includes('-') && container && window.parent) {
            const con = container.querySelector('div.con');
            let nextHref = '';
            let nextChapter = '';
            const prenexts = document.querySelectorAll('div.prenext a');
            for (const element of prenexts) {
                if (element instanceof HTMLAnchorElement) {
                    if (element.textContent == '下一页') {
                        nextHref = element.href;
                        break;
                    }
                    if (element.textContent == '下一章') {
                        nextChapter = element.href;
                        break;
                    }
                }
            }
            window.parent.postMessage({ con: con.innerHTML, next: nextHref, nextChapter: nextChapter, href: location.href });
            return;
        }
        const prenexts = container.querySelectorAll('div.prenext a');
        window.addEventListener('message', (e) => {
            console.log("e", e);
            if (e.data.con) {
                const next = document.createElement('div');
                next.className = 'con';
                next.innerHTML = e.data.con;
                container.insertBefore(next, document.querySelector('div.prenext'));
            }
            if (e.data.next) {
                const iframe = document.querySelector('iframe');
                if (iframe) {
                    iframe.src = e.data.next;
                }
                else {
                    const next = document.createElement('iframe');
                    next.src = e.data.next;
                    next.style.width = '100%';
                    container && container.appendChild(next);
                }
            }
            else {
                console.log('no next');
                const iframe = document.querySelector('iframe');
                if (iframe) {
                    iframe.remove();
                }
                const nextChapter = e.data.nextChapter;
                if (nextChapter) {
                    for (const element of prenexts) {
                        if (element instanceof HTMLAnchorElement) {
                            if (element.textContent == '下一页') {
                                element.href = nextChapter;
                                if (nextChapter.endsWith('.html')) {
                                    element.innerText = '下一章';
                                }
                                else {
                                    element.innerText = '返回目录';
                                }
                                break;
                            }
                        }
                    }
                }
            }
        });
        for (const element of prenexts) {
            if (element instanceof HTMLAnchorElement) {
                if (element.textContent == '下一页') {
                    const next = document.createElement('iframe');
                    next.src = element.href;
                    next.style.display = 'none';
                    next.style.width = '100%';
                    container && container.appendChild(next);
                    break;
                }
            }
        }
    }
    if (location.pathname.endsWith('.html')) {
        handleChaperPage();
    }
    else {
        handleBookPage();
    }
})();