芯幻 自动点赞脚本

Automatically likes the post.

このスクリプトの質問や評価の投稿はこちら通報はこちらへお寄せください。
// ==UserScript==
// @name         芯幻 自动点赞脚本
// @namespace    https://bbs.tampermonkey.net.cn/
// @version      0.1.0
// @description  Automatically likes the post.
// @author       古咩
// @match        https://xhcyra.com/*
// @grant        none
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    const observer = new MutationObserver(mutations => {
        mutations.forEach(mutation => {
            mutation.addedNodes.forEach(node => {
                if (node.matches && node.matches('.inn-singular__post__toolbar__item__link')) {
                    handleLikeButton(node);
                }
            });
        });
    });

    // 监听body元素的子节点变化
    const targetNode = document.body;
    const config = { childList: true, subtree: true };

    observer.observe(targetNode, config);

    function handleLikeButton(likeButton) {
        const buttonText = likeButton.querySelector('.poi-icon__text').textContent.trim();
        if (buttonText === '赞') {
            likeButton.click();
            // 防止重复点击,可选:移除观察者或者只运行一次
            // observer.disconnect();
        }
    }
})();