-
Notifications
You must be signed in to change notification settings - Fork 1
/
nationtweaker-settings.js
50 lines (45 loc) · 1.35 KB
/
nationtweaker-settings.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
function loadTweaks() {
chrome.storage.local.get("tweakSettings", function(res) {
if (res.tweakSettings) {
console.log(res.tweakSettings);
tweaks.forEach(function(t, i) {
if (res.tweakSettings[t.function]) {
t.enabled = res.tweakSettings[t.function].enabled;
} else {
t.enabled = false;
}
});
}
makeTweaksForm();
});
}
function makeTweaksForm() {
form = document.querySelector('#tweaks');
tweaks.forEach(function(t, i) {
console.log(t);
html = "";
html += '<label for="' + t.function + '">' + t.name + "</label>";
html += '<input type="checkbox" name="' + t.function + '" ';
if (t.enabled) {
html += "checked";
}
html += '><br>';
html += '<span class="description">' + t.description + '</span><br>';
if (t.suggestLink) {
html += '<a class="suggest" href="' + t.suggestLink + '" target="_blank">Tell NationBuilder to properly implement this</a><br>';
}
html += '<br>';
form.innerHTML = html + form.innerHTML;
});
}
function saveTweaks(e) {
tweakSettings = {};
tweaks.forEach(function(t, i) {
tweakSettings[t.function] = {"enabled": document.querySelector('input[name="' + t.function + '"]').checked};
});
chrome.storage.local.set({
tweakSettings: tweakSettings
});
}
document.addEventListener("DOMContentLoaded", loadTweaks);
document.querySelector("form").addEventListener("submit", saveTweaks);