aboutsummaryrefslogtreecommitdiff
path: root/config/qutebrowser/greasemonkey/slack.js
blob: 2f1eeef3f3da777ac09815ba802e850c0e2ee192 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// ==UserScript==
// @name               Slack helper
// @namespace          phenax.github.io
// @version            0.0.0
// @description        Slack helper
// @author             Akshay Nair
// @match              *://app.slack.com/*
// ==/UserScript==

const keys = {};

document.addEventListener('keydown', (e) => {
  if (keys[e.key] && e.ctrlKey) {
    keys[e.key]();
  }
});

const notificationsButtons = () => document.querySelectorAll('[data-qa="banner"][class*=notifications] button');

let count = 0;
const timer = setInterval(() => {
  const $btns = notificationsButtons();

  console.log('>> [GM-N] Notification buttons', $btns);

  Array.from($btns)
    .filter($btn => $btn.textContent.match(/enable.*notification/gi))
    .forEach($btn => {
      $btn && $btn.click();
      clearInterval(timer);
      console.log('>> [GM-N] Enabled notifications')
    });

  if (count > 10) clearInterval(timer);
  count += 1;
}, 1000);