Auto Close Slack Tab on Redirect

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

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(Tôi đã có Trình quản lý tập lệnh người dùng, hãy cài đặt nó!)

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.

(I already have a user style manager, let me install it!)

// ==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);
})();