動畫瘋 自動展開「留言板」之前留言

當滾動到頁面底部時,自動點擊展開之前留言按鈕。

// ==UserScript==
// @name         動畫瘋 自動展開「留言板」之前留言
// @version      1.0
// @description  當滾動到頁面底部時,自動點擊展開之前留言按鈕。
// @author       movwei
// @license      MIT
// @match        https://ani.gamer.com.tw/animeVideo.php?sn=*
// @grant        none
// @namespace https://greasyfork.org/users/1041101
// ==/UserScript==

(function() {
    'use strict';

    function simulateClick(element) {
        if (element) {
            var event = new MouseEvent('click', {
                bubbles: true,
                cancelable: true,
                view: window
            });
            element.dispatchEvent(event);
        }
    }

    function isPageBottom() {
        return (window.innerHeight + window.scrollY) >= document.body.offsetHeight - 2;
    }

    function checkAndClick() {
        if (isPageBottom()) {
            var expandButton = document.querySelector('.c-msg-item.c-more-msg[data-evt-morecomment]');
            if (expandButton) {
                simulateClick(expandButton);
                console.log('已點擊展開按鈕');
            } else {
                console.log('未找到展開按鈕');
            }
        }
    }

    window.addEventListener('scroll', checkAndClick);

})();