Auto Close Slack Tab on Redirect

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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