X/Twitter Image Easy Close

X/Twitter Image Easy Close functionality

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==UserScript==
// @name         X/Twitter Image Easy Close
// @namespace    https://github.com/BD9Max
// @version      1.0
// @description  X/Twitter Image Easy Close functionality
// @author       krbd9max
// @match        https://twitter.com/*
// @match        https://x.com/*
// @license      MIT
// @grant        none
// @icon         https://upload.wikimedia.org/wikipedia/commons/c/ce/X_logo_2023.svg
// ==/UserScript==

(function() {
    'use strict';

    // Function to trigger the native Twitter close action
    const closeImageOverlay = () => {
        const closeButton = document.querySelector('[data-testid="app-bar-close"]');
        if (closeButton) {
            closeButton.click();
        } else {
            // Fallback: If the button isn't found, use the browser back action to exit the photo URL
            window.history.back();
        }
    };

    document.addEventListener('click', (e) => {
        // Only run if we are currently looking at a photo/media overlay
        if (window.location.pathname.includes('/photo/')) {
            
            // Check if the click is on an interactive UI element (Like, Retweet, Reply buttons)
            // We exclude these so you can still interact with the post without it closing.
            const isControl = e.target.closest('[role="button"]') || 
                              e.target.closest('[role="menuitem"]') ||
                              e.target.closest('[data-testid="KeybindLayer"]');

            if (!isControl) {
                // Prevent the default Twitter click behavior and close the overlay
                e.stopPropagation();
                closeImageOverlay();
            }
        }
    }, true); // Use capture phase to intercept the click immediately
})();