-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
40 lines (35 loc) · 1.03 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
40
function filterFiles(extension) {
chrome.tabs.executeScript({
code: 'var extension = "' + extension + '";'
}, function() {
chrome.tabs.executeScript({file: 'filterFiles.js'});
});
}
function createOption(extension) {
const option = document.createElement('option');
option.value = extension;
const text = document.createTextNode('.' + extension);
option.appendChild(text);
return option;
}
function receiveMessage(extensions) {
const select = document.getElementById('dropdown');
for (const extension of Object.keys(extensions)) {
const option = createOption(extension);
select.appendChild(option);
}
}
function addOptions(callback) {
chrome.runtime.onMessage.addListener(function(extensions) {
receiveMessage(extensions);
});
chrome.tabs.executeScript({file: 'addOptions.js'}, callback);
}
function addChangeListener() {
dropdown.addEventListener('change', () => {
filterFiles(dropdown.value);
});
}
document.addEventListener('DOMContentLoaded', () => {
addOptions(addChangeListener);
});