Fix X button

Fixes the faulty new X button

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

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

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Fix X button
// @namespace    https://twitter.com/
// @version      1.1
// @description  Fixes the faulty new X button
// @author       You
// @match        https://twitter.com/
// @match        https://*.twitter.com/
// @match        https://twitter.com/*
// @match        https://*.twitter.com/*
// @match        https://x.com/
// @match        https://*.x.com/
// @match        https://x.com/*
// @match        https://*.x.com/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=twitter.com
// @grant        window.close
// @license      JSON
// ==/UserScript==

(function() {
    'use strict';

    const closeTab = () => {
        // in case window.close doesn't work, we need to have a fallback
        document.head.innerHTML = "<style>body { color: orange; background: black }</style>"
        document.body.innerHTML = "It's now safe to turn off your computer."

        // close the tab
        window.close()
    }

    const fixSvgElement = (v) => {
        if(v.innerHTML.includes("M18.244 2.25h3.308l-7.227 8.26 8.502 11.24H16.17l-5.214-6.817L4.99 21.75H1.68l7.73-8.835L1.254 2.25H8.08l4.713 6.231zm-1.161 17.52h1.833L7.084 4.126H5.117z")) { // filter to the X button
            v.style.cursor = "pointer";
            v.onclick = closeTab
        }
    }
    const observer = new MutationObserver(mutations => {
        Array.from(document.getElementsByTagName("svg")).forEach(fixSvgElement);
    });

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

    Array.from(document.getElementsByTagName("svg")).forEach(fixSvgElement);
})();