From f1cf59ce2df9204f818cfd038538a2a31a5c2262 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Mon, 21 Dec 2020 18:52:51 +0530 Subject: Adds qutebrowser config --- config/qutebrowser/greasemonkey/whatsapp.js | 57 +++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 config/qutebrowser/greasemonkey/whatsapp.js (limited to 'config/qutebrowser/greasemonkey/whatsapp.js') diff --git a/config/qutebrowser/greasemonkey/whatsapp.js b/config/qutebrowser/greasemonkey/whatsapp.js new file mode 100644 index 0000000..3bd1ab5 --- /dev/null +++ b/config/qutebrowser/greasemonkey/whatsapp.js @@ -0,0 +1,57 @@ +// ==UserScript== +// @name Whatsapp helper +// @namespace phenax.github.io +// @version 0.0.0 +// @description Whatsapp helper +// @author Akshay Nair +// @match *://web.whatsapp.com/* +// ==/UserScript== + + +const getPosition = $el => parseInt($el.style.transform.match(/translateY\((.*)\)/)[1], 10); + +const getContacts = () => Array.from(document + .querySelectorAll('#pane-side > div:nth-child(1) > div > div > div')) + .sort(($a, $b) => getPosition($a) - getPosition($b)) + +const getNext = () => { + const list = getContacts(); + const current_selected = list.findIndex($el => !!$el.querySelector('[aria-selected=true]')); + return list[current_selected + 1]; +}; +const getPrev = () => { + const list = getContacts(); + const current_selected = list.findIndex($el => !!$el.querySelector('[aria-selected=true]')); + return current_selected <= 0 ? null : list[current_selected - 1]; +}; + +const clickableElem = $el => $el && $el.querySelector('[aria-selected] > div'); + +const click = $el => $el && $el.dispatchEvent(new MouseEvent('mousedown', { + screenX: 5, + screenY: 5, + bubbles: true, + cancellable: true, + relatedTarget: $el, +})); + +const keys = { + j: () => click(clickableElem(getNext())), + k: () => click(clickableElem(getPrev())), +}; + +document.addEventListener('keydown', (e) => { + if (keys[e.key] && e.ctrlKey) { + keys[e.key](); + } +}); + +const timer = setInterval(() => { + if (Notification.permission !== 'default') { + clearInterval(timer); + return; + } + + Notification.requestPermission().then(console.log); +}, 1000); + -- cgit v1.3.1