Skip to content

Instantly share code, notes, and snippets.

@io41
Last active August 5, 2024 11:58
Show Gist options
  • Save io41/304b1af0f83f82dd4408612b31bb25b5 to your computer and use it in GitHub Desktop.
Save io41/304b1af0f83f82dd4408612b31bb25b5 to your computer and use it in GitHub Desktop.
// ==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
// @updateURL https://gist.github.com/io41/304b1af0f83f82dd4408612b31bb25b5/raw/auto-close-slack-tab-on-redirect.user.js
// @downloadURL https://gist.github.com/io41/304b1af0f83f82dd4408612b31bb25b5/raw/auto-close-slack-tab-on-redirect.user.js
// @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);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment