Skip to content

Commit

Permalink
allow a user to focus on the contact searchbox via CMD+K (similar to …
Browse files Browse the repository at this point in the history
…Slack)
  • Loading branch information
Vitaly Belman committed Mar 22, 2016
1 parent a09bda1 commit 70940f9
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 1 deletion.
27 changes: 27 additions & 0 deletions app/js/injected.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
(function () {

console.log("Waiting for DOMContentLoaded");
document.addEventListener('DOMContentLoaded', function () {
console.log("DOMContentLoaded event");

// pass in the target node, as well as the observer options
var observer = new MutationObserver(function (mutations) {
console.log("Mutations occurred: ", mutations.length);
var inputSearch = document.querySelector("input.input-search");
if (inputSearch) {
console.log("Adding event listeners");

document.addEventListener("keydown", function (event) {
if (event.keyCode === 75 && event.metaKey === true) inputSearch.focus()
});

console.log("Disconnecting the observer");
observer.disconnect();
}
});

var config = {childList: true, subtree: true};
observer.observe(document.querySelector("body"), config);

}, false);
})();
5 changes: 4 additions & 1 deletion app/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
var NativeImage = require('native-image');
var BrowserWindow = require('browser-window');

var join = require('path').join;

global.onlyOSX = function(callback) {
if (process.platform === 'darwin') {
return Function.bind.apply(callback, this, [].slice.call(arguments, 0));
Expand Down Expand Up @@ -140,7 +142,8 @@
"min-height": 600,
"type": "toolbar",
"node-integration": false,
"title": "WhatsApp"
"title": "WhatsApp",
"preload": join(__dirname, 'js', 'injected.js')
});

whatsApp.window.loadUrl('https://web.whatsapp.com', {
Expand Down
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ This is **NOT** an official product. This project does not attempt to reverse en
* Open links in browser.
* Badge with the number of notifications in the dock/taskbar.
* Dock icon bounces when a new message is received.
* Focus on contact search input via CMD+K (WIN+K)
* A couple of things can be configured:
* Display or not the avatars
* Display or not the preview of the messages
Expand Down

0 comments on commit 70940f9

Please sign in to comment.