Copy X Timeline Text

在X.com上添加按钮以复制Home timeline的文字,并添加跳转到intumu.com的按钮

目前為 2025-03-09 提交的版本,檢視 最新版本

// ==UserScript==
// @name         Copy X Timeline Text
// @namespace    http://tampermonkey.net/
// @version      0.4
// @description  在X.com上添加按钮以复制Home timeline的文字,并添加跳转到intumu.com的按钮
// @author       Civilpy
// @license MIT
// @match        https://x.com/*
// @grant        GM_setClipboard
// ==/UserScript==

(function() {
    'use strict';

    // 创建容器div来容纳两个按钮
    const buttonContainer = document.createElement('div');
    buttonContainer.style.position = 'fixed';
    buttonContainer.style.right = '20px';
    buttonContainer.style.top = '50%';
    buttonContainer.style.transform = 'translateY(-50%)';
    buttonContainer.style.zIndex = '9999';
    buttonContainer.style.display = 'flex';
    buttonContainer.style.flexDirection = 'column';
    buttonContainer.style.gap = '10px'; // 按钮间距

    // 创建复制按钮
    const copyButton = document.createElement('button');
    copyButton.textContent = '复制 Timeline';
    copyButton.style.padding = '10px 15px';
    copyButton.style.backgroundColor = '#1DA1F2'; // X/Twitter蓝色
    copyButton.style.color = 'white';
    copyButton.style.border = 'none';
    copyButton.style.borderRadius = '5px';
    copyButton.style.cursor = 'pointer';

    // 复制按钮悬停效果
    copyButton.addEventListener('mouseover', () => {
        copyButton.style.backgroundColor = '#1791D6';
    });
    copyButton.addEventListener('mouseout', () => {
        copyButton.style.backgroundColor = '#1DA1F2';
    });

    // 创建跳转按钮
    const visitButton = document.createElement('button');
    visitButton.textContent = '访问 我的主页';
    visitButton.style.padding = '10px 15px';
    visitButton.style.backgroundColor = '#FF5733'; // 橙色,与复制按钮区分
    visitButton.style.color = 'white';
    visitButton.style.border = 'none';
    visitButton.style.borderRadius = '5px';
    visitButton.style.cursor = 'pointer';

    // 跳转按钮悬停效果
    visitButton.addEventListener('mouseover', () => {
        visitButton.style.backgroundColor = '#E64A2E';
    });
    visitButton.addEventListener('mouseout', () => {
        visitButton.style.backgroundColor = '#FF5733';
    });

    // 复制按钮点击事件
    copyButton.addEventListener('click', () => {
        const targetDiv = document.querySelector('div[aria-label="Home timeline"]');
        
        if (targetDiv) {
            const textContent = targetDiv.innerText || targetDiv.textContent;
            
            if (textContent) {
                GM_setClipboard(textContent);
                copyButton.textContent = '已复制!';
                copyButton.style.backgroundColor = '#17BF63'; // 成功时绿色
                
                setTimeout(() => {
                    copyButton.textContent = '复制 Timeline';
                    copyButton.style.backgroundColor = '#1DA1F2';
                }, 2000);
            } else {
                alert('找到时间线,但没有可复制的文本内容');
            }
        } else {
            alert('未找到Home timeline,可能页面尚未加载完成');
        }
    });

    // 跳转按钮点击事件
    visitButton.addEventListener('click', () => {
        window.open('https://intumu.com', '_blank'); // 在新标签页打开
    });

    // 将按钮添加到容器
    buttonContainer.appendChild(copyButton);
    buttonContainer.appendChild(visitButton);

    // 添加容器到页面
    function addButtonsToPage() {
        if (!document.body.contains(buttonContainer)) {
            document.body.appendChild(buttonContainer);
        }
    }

    // 观察页面变化
    const observer = new MutationObserver(() => {
        addButtonsToPage();
    });

    // 页面加载完成时添加按钮
    window.addEventListener('load', () => {
        addButtonsToPage();
        observer.observe(document.body, {
            childList: true,
            subtree: true
        });
    });

    // 初始加载检查
    if (document.readyState === 'complete') {
        addButtonsToPage();
    }
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址