diff options
| author | Akshay Nair <phenax5@gmail.com> | 2020-12-21 18:52:51 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2020-12-21 18:52:51 +0530 |
| commit | f1cf59ce2df9204f818cfd038538a2a31a5c2262 (patch) | |
| tree | 35b0a21501615b7551514262b96e9d8113375cbc /config/qutebrowser/greasemonkey/whatsapp.js | |
| parent | 6ff5a17adcf1ed72cd2f1c7bff606bdd3352b3bb (diff) | |
| download | nixos-config-f1cf59ce2df9204f818cfd038538a2a31a5c2262.tar.gz nixos-config-f1cf59ce2df9204f818cfd038538a2a31a5c2262.zip | |
Adds qutebrowser config
Diffstat (limited to 'config/qutebrowser/greasemonkey/whatsapp.js')
| -rw-r--r-- | config/qutebrowser/greasemonkey/whatsapp.js | 57 |
1 files changed, 57 insertions, 0 deletions
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); + |
