StackExchange chat links

Adds a chat link to the left hand nav of the home page of all Stack sites followed by a lightly filtered list of recently active chat rooms

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

You will need to install a user script manager extension to install this script.

(I already have a user script manager, let me install it!)

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.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name StackExchange chat links
// @namespace http://ostermiller.org/
// @version 1.00
// @description Adds a chat link to the left hand nav of the home page of all Stack sites followed by a lightly filtered list of recently active chat rooms
// @include /https?\:\/\/([a-z\.]*\.)?(stackexchange|askubuntu|superuser|serverfault|stackoverflow|answers\.onstartups)\.com\/$/
// @exclude *://chat.stackoverflow.com/*
// @exclude *://chat.stackexchange.com/*
// @exclude *://chat.*.stackexchange.com/*
// @exclude *://api.*.stackexchange.com/*
// @exclude *://data.stackexchange.com/*
// @connect chat.stackoverflow.com
// @connect chat.stackexchange.com
// @connect chat.meta.stackexchange.com
// @grant GM_xmlhttpRequest
// ==/UserScript==
(function() {
    'use strict';
    var base='https://chat.stackexchange.com/'
    var nav = $('.left-sidebar .nav-links .nav-links')
    var chatlink=$('<li>').html('<a class="pl8 js-gps-track nav-links--link" href="'+base+'?tab=site&sort=active&host='+location.hostname+'">Chat</a>')
    nav.append(chatlink)
    var chatlinks=$('<ol class="nav-links">')
    chatlink.append(chatlinks)
    GM_xmlhttpRequest({
        method: "GET",
        url: base+'?tab=site&sort=active&host='+location.hostname,
        responseType: 'html',
        onload:function (resp) {
            $(resp.responseText).find('.roomcard').each(function(){
                var name=$(this).find('.room-name').html().replace('"/', '"'+base)
                if (!name.match(/((discussion between)|(room for).* and )|(discussion on answer|question)/i)){
                    var act=$(this).find('.last-activity').html().replace('"/', '"'+base)
                    var daysago = act.match(/([0-9])+d ago/)
                    if (!daysago || parseInt(daysago) <= 7) chatlinks.append($('<li>').html(name + " " + act))
                }
            });
        }
    });
})();