Skip to content

Instantly share code, notes, and snippets.

@pl12133
Created April 30, 2016 19:12
Show Gist options
  • Save pl12133/36ace503d3d212a8982f4e1f2b22541a to your computer and use it in GitHub Desktop.
Save pl12133/36ace503d3d212a8982f4e1f2b22541a to your computer and use it in GitHub Desktop.
function handleKeydown() {
var unreadSelector = '.channel.channel-text.unread > a';
var unreadIndex = 0;
var getUnread = () => document.querySelectorAll(unreadSelector);
var numUnread = getUnread().length;
return function (e) {
// Hotkey is CTRL + B (case insensitive)
if (e && e.ctrlKey && e.keyCode == 'B'.charCodeAt(0)) {
var newLength = getUnread().length;
var unreadDelta = numUnread - newLength;
numUnread = newLength;
unreadIndex -= unreadDelta;
unreadIndex = unreadIndex >= newLength
? 0
: unreadIndex;
getUnread()[unreadIndex++].click();
}
}
}
document.addEventListener('keydown', handleKeydown());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment