Greasy Fork is available in English.

Auto Close Slack Tab on Redirect

Auto close Slack's "We’ve redirected you to the desktop app." tabs.

// ==UserScript==
// @name         Auto Close Slack Tab on Redirect
// @namespace    https://*.slack.com/archives/*
// @version      0.3
// @description  Auto close Slack's "We’ve redirected you to the desktop app." tabs.
// @author       Tim Kersten
// @match        https://klarna.slack.com/archives/*
// @grant        none
// @homepageURL  https://gist.github.com/io41/304b1af0f83f82dd4408612b31bb25b5
// @license MIT
// ==/UserScript==

(function() {
    'use strict';

    // The text to search for
    const redirectText = "We’ve redirected you to the desktop app.";

    // Function to check for the redirect element
    function checkForRedirect() {
        const redirectElement = document.querySelector('p.p-ssb_redirect__loading_messages');
        if (redirectElement && redirectElement.innerText.includes(redirectText)) {
            window.close();
        }
    }

    // Check for the element 2 seconds after loading
    setTimeout(checkForRedirect, 2000);
})();