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

  1. // ==UserScript==
  2. // @name StackExchange chat links
  3. // @namespace http://ostermiller.org/
  4. // @version 1.00
  5. // @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
  6. // @include /https?\:\/\/([a-z\.]*\.)?(stackexchange|askubuntu|superuser|serverfault|stackoverflow|answers\.onstartups)\.com\/$/
  7. // @exclude *://chat.stackoverflow.com/*
  8. // @exclude *://chat.stackexchange.com/*
  9. // @exclude *://chat.*.stackexchange.com/*
  10. // @exclude *://api.*.stackexchange.com/*
  11. // @exclude *://data.stackexchange.com/*
  12. // @connect chat.stackoverflow.com
  13. // @connect chat.stackexchange.com
  14. // @connect chat.meta.stackexchange.com
  15. // @grant GM_xmlhttpRequest
  16. // ==/UserScript==
  17. (function() {
  18. 'use strict';
  19. var base='https://chat.stackexchange.com/'
  20. var nav = $('.left-sidebar .nav-links .nav-links')
  21. var chatlink=$('<li>').html('<a class="pl8 js-gps-track nav-links--link" href="'+base+'?tab=site&sort=active&host='+location.hostname+'">Chat</a>')
  22. nav.append(chatlink)
  23. var chatlinks=$('<ol class="nav-links">')
  24. chatlink.append(chatlinks)
  25. GM_xmlhttpRequest({
  26. method: "GET",
  27. url: base+'?tab=site&sort=active&host='+location.hostname,
  28. responseType: 'html',
  29. onload:function (resp) {
  30. $(resp.responseText).find('.roomcard').each(function(){
  31. var name=$(this).find('.room-name').html().replace('"/', '"'+base)
  32. if (!name.match(/((discussion between)|(room for).* and )|(discussion on answer|question)/i)){
  33. var act=$(this).find('.last-activity').html().replace('"/', '"'+base)
  34. var daysago = act.match(/([0-9])+d ago/)
  35. if (!daysago || parseInt(daysago) <= 7) chatlinks.append($('<li>').html(name + " " + act))
  36. }
  37. });
  38. }
  39. });
  40. })();