Skip to content

Instantly share code, notes, and snippets.

@pgebheim
Last active November 9, 2017 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pgebheim/f77dd4a56fe2c18c4309492a081a6201 to your computer and use it in GitHub Desktop.
Save pgebheim/f77dd4a56fe2c18c4309492a081a6201 to your computer and use it in GitHub Desktop.
(function() {
var loadScript = function(s) {
var script = document.createElement('script');
script.src = s;
document.body.appendChild(script);
};
var simulatedClick = function(target, options) {
var event = target.ownerDocument.createEvent('MouseEvents'),
options = options || {},
opts = { // These are the default values, set up for un-modified left clicks
type: 'click',
canBubble: true,
cancelable: true,
view: target.ownerDocument.defaultView,
detail: 1,
screenX: 0, //The coordinates within the entire page
screenY: 0,
clientX: 0, //The coordinates within the viewport
clientY: 0,
ctrlKey: false,
altKey: false,
shiftKey: false,
metaKey: false, //I *think* 'meta' is 'Cmd/Apple' on Mac, and 'Windows key' on Win. Not sure, though!
button: 0, //0 = left, 1 = middle, 2 = right
relatedTarget: null,
};
//Merge the options with the defaults
for (var key in options) {
if (options.hasOwnProperty(key)) {
opts[key] = options[key];
}
}
//Pass in the options
event.initMouseEvent( opts.type, opts.canBubble, opts.cancelable, opts.view, opts.detail, opts.screenX, opts.screenY, opts.clientX, opts.clientY, opts.ctrlKey, opts.altKey, opts.shiftKey, opts.metaKey, opts.button, opts.relatedTarget)
//Fire the event
target.dispatchEvent(event);
};
loadScript('https://cdnjs.cloudflare.com/ajax/libs/mousetrap/1.6.1/mousetrap.min.js');
var wait = setInterval(function() {
if(typeof window.Mousetrap !== "undefined") {
clearInterval(wait);
Mousetrap(document.querySelector("#app-mount")).bind("ctrl+shift+\\", function() {
var el = document.querySelector('.message-group:last-child .message:last-child .message-text:last-child > .btn-reaction');
simulatedClick(el);
});
}
}, 100);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment