aboutsummaryrefslogtreecommitdiff
path: root/config/qutebrowser/greasemonkey/slack.js
blob: b1d6cc4dd0db2e790f2eb478d75d5eb8a2a4f693 (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
// ==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('>> Notification buttons', $btns);

  Array.from($btns)
    .filter($btn => $btn.textContent.match(/enable.*notification/))
    .forEach($btn => {
      $btn && $btn.click();
      clearInterval(timer);
    });

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