Switch Slack channels.

Use ALT+PageUp/PageDown to navigate Slack channels.

Dovrai installare un'estensione come Tampermonkey, Greasemonkey o Violentmonkey per installare questo script.

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

Dovrai installare un'estensione come Tampermonkey o Violentmonkey per installare questo script.

Dovrai installare un'estensione come Tampermonkey o Userscripts per installare questo script.

Dovrai installare un'estensione come ad esempio Tampermonkey per installare questo script.

Dovrai installare un gestore di script utente per installare questo script.

(Ho già un gestore di script utente, lasciamelo installare!)

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione come ad esempio Stylus per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

Dovrai installare un'estensione per la gestione degli stili utente per installare questo stile.

(Ho già un gestore di stile utente, lasciamelo installare!)

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