X to Unroll Redirect (Yellow Icon, Tweet-specific)

Add a yellow Unroll button next to the like button on X (Twitter) individual tweet pages

目前為 2024-09-25 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         X to Unroll Redirect (Yellow Icon, Tweet-specific)
// @namespace    http://tampermonkey.net/
// @version      0.3
// @description  Add a yellow Unroll button next to the like button on X (Twitter) individual tweet pages
// @match        https://twitter.com/*
// @match        https://x.com/*
// @grant        none
// @license MIT

// ==/UserScript==

(function() {
    'use strict';

    function addUnrollButton() {
        // Check if we're on an individual tweet page
        if (!window.location.pathname.includes('/status/')) return;

        const tweetActions = document.querySelector('div[role="group"]');
        if (!tweetActions || document.querySelector('#unrollButton')) return;

        const unrollButton = document.createElement('div');
        unrollButton.id = 'unrollButton';
        unrollButton.role = 'button';
        unrollButton.ariaLabel = 'Unroll thread';
        unrollButton.innerHTML = `
            <div dir="ltr" class="css-1rynq56 r-bcqeeo r-qvutc0 r-37j5jr r-a023e6 r-rjixqe r-16dba41 r-1awozwy r-6koalj r-1h0z5md r-o7ynqc r-clp7b1 r-3s2u2q">
                <svg viewBox="0 0 24 24" width="20" height="20">
                    <g><path fill="#FFD700" d="M7.8 21c-.3 0-.5-.1-.7-.3-.5-.5-.4-1.2.1-1.6L14.9 12 7.2 4.9c-.5-.4-.6-1.1-.1-1.6.4-.5 1.1-.6 1.6-.1l8.8 8c.3.3.4.7.4 1.1s-.2.8-.4 1.1l-8.8 8c-.3.2-.6.3-.9.3z"></path></g>
                </svg>
            </div>
        `;

        unrollButton.style.cssText = `
            display: inline-flex;
            align-items: center;
            padding: 0 12px;
            cursor: pointer;
        `;

        unrollButton.addEventListener('click', function(e) {
            e.preventDefault();
            e.stopPropagation();
            const tweetId = window.location.pathname.split('/status/')[1];
            if (tweetId) {
                window.open(`https://unrollnow.com/status/${tweetId}`, '_blank');
            } else {
                alert('Unable to find tweet ID. Make sure you are on a tweet page.');
            }
        });

        tweetActions.appendChild(unrollButton);
    }

    // Run the function initially and also whenever the URL changes
    const observer = new MutationObserver((mutations) => {
        for (let mutation of mutations) {
            if (mutation.type === 'childList') {
                addUnrollButton();
            }
        }
    });

    observer.observe(document.body, { childList: true, subtree: true });

    // Also run when the page loads and when the URL changes
    window.addEventListener('load', addUnrollButton);
    window.addEventListener('popstate', addUnrollButton);
})();