diff options
| author | Akshay Nair <phenax5@gmail.com> | 2021-09-14 13:34:19 +0530 |
|---|---|---|
| committer | Akshay Nair <phenax5@gmail.com> | 2021-09-14 13:34:19 +0530 |
| commit | f819aa3afea420925fe4c91a71a2756d5ed04b80 (patch) | |
| tree | 51485da02eda97596faf55aec4881af8134b1e72 /config/qutebrowser/greasemonkey/google-meet.js | |
| parent | 994bda7f51d6967087832218d7d3613f37960c9f (diff) | |
| download | nixos-config-f819aa3afea420925fe4c91a71a2756d5ed04b80.tar.gz nixos-config-f819aa3afea420925fe4c91a71a2756d5ed04b80.zip | |
qutebrowser config save
Diffstat (limited to 'config/qutebrowser/greasemonkey/google-meet.js')
| -rw-r--r-- | config/qutebrowser/greasemonkey/google-meet.js | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/config/qutebrowser/greasemonkey/google-meet.js b/config/qutebrowser/greasemonkey/google-meet.js new file mode 100644 index 0000000..37a163b --- /dev/null +++ b/config/qutebrowser/greasemonkey/google-meet.js @@ -0,0 +1,71 @@ +// ==UserScript== +// @name Google meet mute indicator +// @namespace phenax.github.io +// @version 0.0.0 +// @description Google meet mute indicator +// @author Akshay Nair +// @match *://meet.google.com/* +// ==/UserScript== + +(() => { + const log = console.log.bind(console, '[MeetingBtns]'); + const $$ = document.querySelectorAll.bind(document); + + const $indicator = document.createElement('div'); + Object.assign($indicator.style, { + backgroundColor: 'red', + width: '200px', + height: '100px', + position: 'fixed', + zIndex: 90000, + left: 0, + top: 0, + opacity: 0, + }); + + const getMuteBtns = () => Array.from($$('[data-is-muted][role="button"]')); + + const updateMuteState = () => { + try { + const $btns = getMuteBtns(); + const $mutedBtns = $btns.filter($btn => $btn.dataset.isMuted === 'true'); + Object.assign($indicator.style, { + opacity: $mutedBtns.length === $btns.length ? 0 : 1, + }); + } catch (e) { log('update error', e); } + }; + + const observer = new MutationObserver(diffs => { + log('mutation observer'); + const muteChange = diffs.find(d => d.attributeName === 'data-is-muted'); + if (!!muteChange) { + log('updating mute state'); + updateMuteState(); + } + }); + + const init = () => { + const $muteBtns = getMuteBtns(); + log('initializing', $muteBtns); + document.body.appendChild($indicator); + + $muteBtns.forEach($btn => { + observer.observe($btn, { attributes: true, attributeFilter: ['data-is-muted'] }); + updateMuteState(); + }); + + if (window.$$$muteObserver) window.$$$muteObserver.disconnect(); + window.$$$muteObserver = observer; + }; + + const timer = setInterval(() => { + const $btns = getMuteBtns(); + const hasJoinedMeeting = $$('[data-meeting-code]').length === 0; + log('checking if joined...', hasJoinedMeeting); + if ($btns.length > 0 && hasJoinedMeeting) { + setTimeout(() => init(), 1000); + clearInterval(timer); + } + }, 500); +})(); + |
