forked from alexwestco/what_matters_most
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
83 lines (65 loc) · 2.43 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
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
document.addEventListener("DOMContentLoaded", listExtensions);
function listExtensions() {
let newTabExtensions = [];
let options = document.querySelector("#options");
chrome.management.getAll(function (response) {
response.sort(compare);
response.forEach((installedExtension) => {
installedExtension.permissions.forEach((permission) => {
if (permission === "newTabPageOverride") {
//chrome.extension.getBackgroundPage().console.log(installedExtension.name);
newTabExtensions.push({
name: installedExtension.name,
description: installedExtension.description,
id: installedExtension.id,
});
}
});
});
checkboxes = [];
extensions = [];
chrome.storage.sync.get("extensions", function (data) {
//chrome.extension.getBackgroundPage().console.log('Now ------------------> extensions are ')
storageExtensions = data.extensions;
//chrome.extension.getBackgroundPage().console.log(extensions)
newTabExtensions.forEach((extension) => {
let option = document.createElement("div");
option.classList.add("option");
let checkbox = document.createElement("input");
checkbox.type = "checkbox";
checkbox.value = "value";
checkbox.classList.add("extension");
checkbox.dataset.name = extension.name;
checkbox.id = extension.id;
checkbox.checked = storageExtensions.filter(
(i) => i.id === extension.id
).length;
let label = document.createElement("label");
label.htmlFor = extension.id;
label.innerHTML = `${extension.name.bold()}: ${extension.description}`;
checkboxes.push(checkbox);
option.appendChild(checkbox);
option.appendChild(label);
options.appendChild(option)
});
});
});
document.querySelector("#btn").onclick = function () {
let extensionsToSwitch = [];
document.querySelectorAll("input.extension").forEach((option) => {
if (option.checked)
extensionsToSwitch.push({
id: option.id,
name: option.dataset.name,
});
});
console.log(extensionsToSwitch);
chrome.runtime.sendMessage({ extensionsToSwitch }, function (response) {});
//chrome.extension.getBackgroundPage().console.log(checkboxes)
};
};
const compare = (a, b) => {
if (a.name < b.name) return -1;
if (a.name > b.name) return 1;
return 0;
};