From d0bb3313bd72c80b5eb5cd1c0f6bc24411850259 Mon Sep 17 00:00:00 2001 From: ShadyThGod Date: Thu, 7 Nov 2019 16:57:07 +0530 Subject: [PATCH] Update whatsapp.js 1. Add zoom function on mouse wheel scroll. 2. Clicking a link will open it in an external browser. --- src/windows/main/whatsapp.js | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/windows/main/whatsapp.js b/src/windows/main/whatsapp.js index ed1b2936..d43ee809 100644 --- a/src/windows/main/whatsapp.js +++ b/src/windows/main/whatsapp.js @@ -23,6 +23,8 @@ window.onload = () => { window.location.reload(); } + // Message Indicator + // Using MutationObserver to check for changes in the title of the WhatsApp page and sending an IPC message to the main process new MutationObserver(function(mutations) { let title = mutations[0].target.innerText; let titleRegEx = /([0-9]+)/; @@ -35,4 +37,32 @@ window.onload = () => { characterData: true } ); + + // Mouse wheel event listener for zoom + document.body.addEventListener('wheel', e => { + // Mouse wheel delta value. (+1 when scroll up | -1 when scroll down) + const delta = Math.sign(e.deltaY); + + if (e.ctrlKey) { + switch (delta) { + case -1: + ipcRenderer.send('zoom-in'); + break; + + case +1: + ipcRenderer.send('zoom-out'); + break; + + default: + break; + } + } + }); + + // Open links in external browser + document.body.addEventListener('click', e => { + if (e.target.tagName === 'A') { + ipcRenderer.send('link-open', e.target.href); + } + }); } \ No newline at end of file