Created
May 8, 2019 00:21
-
-
Save deecewan/d43d99ae3b6f018ee5dd6bdfda251674 to your computer and use it in GitHub Desktop.
Tampermonkey scipt to change chat windows with a keypress
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Chat window changer | |
// @namespace http://deecewan.com | |
// @version 0.1 | |
// @description try to take over the world! | |
// @author David Buchan-Swanson | |
// @match https://tanda.facebook.com/chat/t/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
document.addEventListener('keyup', e => { | |
if (!e.ctrlKey) { | |
// you must press alt | |
return; | |
} | |
if (e.keyCode < 49 || e.keyCode > 57) { | |
// only handle number keys (1-9) | |
return; | |
} | |
e.preventDefault(); | |
const number = e.keyCode - 49; | |
const items = document | |
.querySelector('[aria-label="Conversation List"') | |
.querySelectorAll('li'); | |
const selected = items[number]; | |
if (!selected) { | |
// who knows | |
return; | |
} | |
selected.querySelector('a').click(); | |
}); | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment