Slack automatic redirect (open with browser)

automatically use Slack in browser (web version)

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

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

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name        Slack automatic redirect (open with browser)
// @namespace   slackwebversion
// @description automatically use Slack in browser (web version)
// @include     https://*.slack.com/*
// @version     1
// @license MIT
// ==/UserScript==
console.log('started script on Slack, title = "', document.title, '"');

const slack_title = "Weiterleitung erfolgt";
const slack_redir = "auch in deinem Browser"; /* "diesen Link auch in deinem Browser öffnen" or "Slack auch in deinem Browser verwenden" */

function redirectFunc() {
    console.log("redirect function started");

    Array.from(document.getElementsByTagName('a')).forEach(link => {
        var txt = link.innerText;
        var uri = link.href;
        console.log("link text=", txt, ", href=", uri);
        if (txt && txt.includes(slack_redir)) {
            console.log("found : URL = ", uri);
            stopped = true; // stop timer while redirecting
            window.location.replace(uri);
            return; /* break; */
        }
    });

    console.log("no link found"); // output this message: if code has reached there, means no appropriate link found (return not working)

}

/* interval timer: https://stackoverflow.com/a/66690340/14776523 */

var i = 0; // counter for the timer
var stopped = false;

function doTimer() {
    if (stopped)
        return;
    console.log("1 second... check", i); // your actual code here, alternatively ...
    redirectFunc(); // ... call an other function here
    if (++i < 15) { // only reset the timer when maximum of 10 times it is fired 
        console.log("reset the timer");
        setTimeout(doTimer, 1000); // reset the timer
    }
    else {
        console.log("timer ended");
    }
}


// check if we are on the startpage
if (document.title.includes(slack_title)) // falls wir auf der Startseite sind
{
    console.log("SLACK startpage detected.");
    setTimeout(doTimer, 1000); // init the first
}