-
Notifications
You must be signed in to change notification settings - Fork 2
/
popup.js
39 lines (34 loc) · 1.05 KB
/
popup.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
var slider = document.getElementById('slider');
var label = document.getElementById('label');
/**
* Sets the slider position and label to reflect a new min PTT length.
*
* @param {number} minPttLength - The new minimum PTT length.
*/
function onMinPttLengthChanged(minPttLength) {
slider.value = minPttLength;
label.innerHTML = minPttLength + 'ms';
}
// Keep our min PTT length in sync with all the others.
chrome.runtime.onMessage.addListener(function(msg, _) {
if (msg.id !== 'min_ptt_length_changed') {
console.debug('Unexpected message "' + msg.id + '" received by popup.');
return false;
}
return onMinPttLengthChanged(msg.value);
});
// Request stored min PTT length from background script when this popup is
// created.
chrome.runtime.sendMessage({
id: 'popup_loaded',
}, onMinPttLengthChanged);
/**
* Updates background script (and subsequently all other popups) with new
* values from this slider.
*/
slider.oninput = function() {
chrome.runtime.sendMessage({
id: 'min_ptt_length_changed',
value: parseInt(this.value),
});
};