Twitter貼文圖片自動按讚

當點擊貼文圖片時,自動按讚

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Twitter貼文圖片自動按讚
// @name:en      TweetImgAutoLike
// @description  當點擊貼文圖片時,自動按讚
// @description:en  When clicking on a Tweet's image, automatically like it.

// @namespace    https://github.com/Max46656
// @version      1.0.0
// @author       Max

// @match        https://twitter.com/*
// @match        https://x.com/*
// @match        https://mobile.twitter.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=x.com
// @license MPL2.0
// ==/UserScript==

class TweetLiker {
    constructor() {
        this.observer = null;
    }

    init() {
        this.observer = new MutationObserver((mutations) => {
            mutations.forEach((mutation) => {
                mutation.addedNodes.forEach((node) => {
                    if (node.nodeType === Node.ELEMENT_NODE &&
                        node.querySelector('div[aria-labelledby="modal-header"] div.r-11yh6sk[style]')) {
                        this.clickLikeButton(node);
                    }
                });
            });
        });

        this.observer.observe(document.body, { childList: true, subtree: true });
        console.log('貼文圖片觀察者啟動');
    }

    clickLikeButton(node) {
        const likeButton = node.querySelector('button[data-testid="like"]');
        if (likeButton) {
            likeButton.click();
            console.log('已喜歡貼文圖片');
        } else {
            console.warn('未找到喜歡按鈕');
        }
    }
}


const johnThebardOfLove = new TweetLiker();
johnThebardOfLove.init();