X Milady Reply Button

Adds a Milady-eyes button under each tweet that replies "milady"

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         X Milady Reply Button
// @namespace    https://tampermonkey.net/
// @version      0.1
// @description  Adds a Milady-eyes button under each tweet that replies "milady"
// @match        https://x.com/*
// @match        https://twitter.com/*
// @grant        none
// @license      MIT
// ==/UserScript==

(function () {
    'use strict';

    const BUTTON_CLASS = 'milady-reply-button';

    function createButton() {
        const btn = document.createElement('button');
        btn.textContent = '👀';
        btn.title = 'Reply "milady"';
        btn.className = BUTTON_CLASS;

        btn.style.border = 'none';
        btn.style.background = 'transparent';
        btn.style.cursor = 'pointer';
        btn.style.fontSize = '18px';
        btn.style.marginLeft = '8px';

        return btn;
    }

    async function replyMilady(article) {
        // Click the native reply button
        const replyButton = article.querySelector('[data-testid="reply"]');
        if (!replyButton) return;

        replyButton.click();

        // Wait for reply dialog to appear
        await new Promise(r => setTimeout(r, 500));

        // Find the text box
        const textbox = document.querySelector('[data-testid="tweetTextarea_0"]');
        if (!textbox) return;

        textbox.focus();
        document.execCommand('insertText', false, 'milady');

        // Small pause so X notices the text
        await new Promise(r => setTimeout(r, 300));

        // Click the send button
        const sendButton = document.querySelector('[data-testid="tweetButtonInline"]');
        if (sendButton && !sendButton.disabled) {
            sendButton.click();
        }
    }

    function enhanceTweet(article) {
        if (article.querySelector(`.${BUTTON_CLASS}`)) return;

        const actionBar = article.querySelector('[role="group"]');
        if (!actionBar) return;

        const btn = createButton();
        btn.addEventListener('click', () => replyMilady(article));
        actionBar.appendChild(btn);
    }

    function scan() {
        document.querySelectorAll('article[data-testid="tweet"]').forEach(enhanceTweet);
    }

    // Initial scan
    scan();

    // Observe future tweets (infinite scroll)
    const observer = new MutationObserver(scan);
    observer.observe(document.body, {
        childList: true,
        subtree: true
    });
})();