NL+ | NodeLoc 增强脚本

NodeLoc 增强脚本

目前为 2024-10-04 提交的版本。查看 最新版本

// ==UserScript==
// @name         NL+ | NodeLoc 增强脚本
// @namespace    https://www.nodeloc.com/
// @version      0.1.6
// @description  NodeLoc 增强脚本
// @run-at       document-end
// @match        https://www.nodeloc.com/*
// @icon         https://www.nodeloc.com/assets/favicon-ptypmduq.png
// @license      gpl-3.0
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    window.onload = function() {
        // 移除页面中的 wghtml 元素
        var observer = new MutationObserver(function(mutations) {
            mutations.forEach(function(mutation) {
                var wghtmlElement = document.getElementById("wghtml");
                if (wghtmlElement) {
                    wghtmlElement.remove();
                    observer.disconnect(); // 移除目标后停止观察
                }
            });
        });

        // 开始观察整个文档的子树
        observer.observe(document.body, { childList: true, subtree: true });

        // 初始检测
        var initialElement = document.getElementById("wghtml");
        if (initialElement) {
            initialElement.remove();
        }

        // 自动点击“Next”按钮实现自动翻页
        function clickNextPage() {
            const nextButton = document.querySelector('.Button[aria-label="Next"]');
            if (nextButton) {
                nextButton.click();
            }
        }

        // 使用 IntersectionObserver 监视是否滚动到底部
        let scrollObserver = new IntersectionObserver((entries) => {
            if (entries[0].isIntersecting) {
                clickNextPage();
            }
        }, {
            rootMargin: '0px 0px 200px 0px' // 触发加载的距离
        });

        // 创建一个触发点
        let trigger = document.createElement('div');
        document.body.appendChild(trigger);
        scrollObserver.observe(trigger);
    };
})();