Switch Slack channels.

Use ALT+PageUp/PageDown to navigate Slack channels.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Switch Slack channels.
// @namespace    http://kevinx.net/
// @version      0.2
// @description  Use ALT+PageUp/PageDown to navigate Slack channels.
// @author       Kevin DeLoach
// @match        http://*.slack.com/*
// @match        https://*.slack.com/*
// @run-at       document-end
// @grant        none
// ==/UserScript==

$(function() {
    var $channels = $('#channel-list'),
        $target = null;

    function elAt(i) {
        return $($channels.children().get(i));
    }

    function selectedOrActive() {
        var $el = $channels.find('li.channel.underline');
        if ($el.size() > 0) {
            return $($el.get(0));
        }
        return $($channels.find('li.channel.active').get(0));
    }
    
    function move(dy) {
        var $active = selectedOrActive(),
            i = $channels.children().index($active),
            j = i + dy;
        j = Math.max(0, Math.min($channels.children().size() - 1, j));
        switchChannel(elAt(j));
    }

    function switchChannel($el) {
        $channels.find('li.channel.underline').removeClass('underline');
        $el.addClass('underline');
        $target = $el;
    }

    $(document.body).on('keyup', function(e) {
        if (e.shiftKey) {
            return;
        }
        if (e.altKey && e.keyCode === 33) {
            move(-1);
        } else if (e.altKey && e.keyCode === 34) {
            move(1);
        } else if ($target) {
            $target.find('a').trigger('click');
            $target = null;
        }
    });
});