forked from FugiTech/google-meet-grid-view
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.js
107 lines (90 loc) · 3.57 KB
/
extension.js
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
;(async function () {
const T = TranslationFactory()
// Construct HTML
document.body.classList = 'not-running'
document.body.innerHTML = `
<div id="not-running">${T('notRunning')}</div>
<div id="no-meeting">${T('noMeeting')}</div>
<label id="enabled">
<input type="checkbox" />
${T('enabled')}
</label>
<div class="spacer"></div>
<label id="show-only-video">
<input type="checkbox" />
${T('showOnlyVideo')}
</label>
<label id="highlight-speaker">
<input type="checkbox" />
${T('highlightSpeaker')}
</label>
<label id="include-own-video">
<input type="checkbox" />
${T('includeOwnVideo')}
</label>
<label id="auto-enable">
<input type="checkbox" />
${T('autoEnable')}
</label>
<div class="spacer"></div>
<label id="screen-capture-mode">
<input type="checkbox" />
${T('screenCaptureMode')}
</label>
<small id="screen-capture-mode-desc">${T('screenCaptureModeDescription')}</small>
<div class="spacer"></div>
<div id="advanced-settings">
<a href="#">${T('advancedSettingsLink')}</a>
</div>
<div class="spacer"></div>
<div id="source-code">
<small>v${browser.runtime.getManifest().version}</small>
<a href="https://github.com/Fugiman/google-meet-grid-view" target="_blank">
${T('sourceCode')}
</a>
</div>
`
// Get state
const tabs = await browser.tabs.query({ active: true, currentWindow: true })
const state = await browser.tabs.sendMessage(tabs[0].id, { type: 'getState' })
if (state.error) return
if (!state.inMeeting) {
document.body.classList = 'no-meeting'
return
}
document.body.classList = 'in-meeting'
for (let [k, v] of Object.entries(state.settings)) {
const i = document.querySelector(`#${k} input`)
if (i) i.checked = v
}
const updateSettings = () => {
document.querySelectorAll('label:not(#enabled)').forEach(el => el.classList.toggle('disabled', !state.settings['enabled']))
document.querySelectorAll('label:not(#enabled) input').forEach(el => (el.disabled = !state.settings['enabled']))
if (state.settings['enabled']) {
document.querySelector('#show-only-video input').checked = state.settings['show-only-video'] && !state.settings['screen-capture-mode']
document.querySelector('#show-only-video input').disabled = state.settings['screen-capture-mode']
document.querySelector('#show-only-video').classList.toggle('disabled', state.settings['screen-capture-mode'])
document.querySelector('#highlight-speaker input').checked = state.settings['highlight-speaker'] && !state.settings['screen-capture-mode']
document.querySelector('#highlight-speaker input').disabled = state.settings['screen-capture-mode']
document.querySelector('#highlight-speaker').classList.toggle('disabled', state.settings['screen-capture-mode'])
}
}
updateSettings()
document.querySelectorAll('label').forEach(el => {
const name = el.id
el.querySelector('input').onchange = async e => {
try {
const response = await browser.tabs.sendMessage(tabs[0].id, { type: 'updateSetting', name, value: e.target.checked })
if (response.error) throw new Error(response.error)
state.settings[name] = e.target.checked
updateSettings()
} catch {
e.target.checked = !e.target.checked
}
}
})
document.querySelector('#advanced-settings a').onclick = e => {
e.preventDefault()
browser.tabs.sendMessage(tabs[0].id, { type: 'updateSetting', name: 'show-settings-overlay', value: true })
}
})()