Changeset View
Changeset View
Standalone View
Standalone View
extension/options.js
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Line(s) | 31 | tabbar.buttons.forEach(function (button) { | |||
---|---|---|---|---|---|
42 | } | 42 | } | ||
43 | }); | 43 | }); | ||
44 | } | 44 | } | ||
45 | 45 | | |||
46 | function extensionCheckboxes() { | 46 | function extensionCheckboxes() { | ||
47 | return document.querySelectorAll("#extensions-selection input[type=checkbox][data-extension]"); | 47 | return document.querySelectorAll("#extensions-selection input[type=checkbox][data-extension]"); | ||
48 | } | 48 | } | ||
49 | 49 | | |||
50 | function loadSettings() { | 50 | function loadSettings(cb) { | ||
51 | storage.get(DEFAULT_EXTENSION_SETTINGS, function (items) { | 51 | storage.get(DEFAULT_EXTENSION_SETTINGS, function (items) { | ||
52 | if (chrome.runtime.lastError) { | 52 | if (chrome.runtime.lastError) { | ||
53 | if (typeof cb === "function") { | ||||
54 | cb(false); | ||||
55 | } | ||||
53 | return; | 56 | return; | ||
54 | } | 57 | } | ||
55 | 58 | | |||
56 | for (var key in items) { | 59 | for (var key in items) { | ||
57 | if (!items.hasOwnProperty(key)) { | 60 | if (!items.hasOwnProperty(key)) { | ||
58 | continue; | 61 | continue; | ||
59 | } | 62 | } | ||
60 | 63 | | |||
61 | var checkbox = document.querySelector("input[type=checkbox][data-extension=" + key + "]"); | 64 | var checkbox = document.querySelector("input[type=checkbox][data-extension=" + key + "]"); | ||
62 | if (!checkbox) { | 65 | if (!checkbox) { | ||
63 | console.warn("Failed to find checkbox for extension", key); | 66 | console.warn("Failed to find checkbox for extension", key); | ||
64 | continue; | 67 | continue; | ||
65 | } | 68 | } | ||
66 | 69 | | |||
67 | var checked = !!items[key].enabled; | 70 | var checked = !!items[key].enabled; | ||
68 | checkbox.checked = checked; | 71 | checkbox.checked = checked; | ||
69 | 72 | | |||
70 | // TODO restore additional stuff if we have it | 73 | // TODO restore additional stuff if we have it | ||
71 | } | 74 | } | ||
75 | | ||||
76 | if (typeof cb === "function") { | ||||
77 | cb(true); | ||||
78 | } | ||||
72 | }); | 79 | }); | ||
73 | } | 80 | } | ||
74 | 81 | | |||
75 | function saveSettings(cb) { | 82 | function saveSettings(cb) { | ||
76 | var settings = {}; | 83 | var settings = {}; | ||
77 | 84 | | |||
78 | for (var key in DEFAULT_EXTENSION_SETTINGS) { | 85 | for (var key in DEFAULT_EXTENSION_SETTINGS) { | ||
79 | if (!DEFAULT_EXTENSION_SETTINGS.hasOwnProperty(key)) { | 86 | if (!DEFAULT_EXTENSION_SETTINGS.hasOwnProperty(key)) { | ||
▲ Show 20 Lines • Show All 45 Lines • ▼ Show 20 Line(s) | 108 | document.addEventListener("DOMContentLoaded", function () { | |||
125 | }); | 132 | }); | ||
126 | 133 | | |||
127 | if (IS_FIREFOX) { | 134 | if (IS_FIREFOX) { | ||
128 | document.querySelectorAll("[data-not-show-in=firefox]").forEach(function (item) { | 135 | document.querySelectorAll("[data-not-show-in=firefox]").forEach(function (item) { | ||
129 | item.style.display = "none"; | 136 | item.style.display = "none"; | ||
130 | }); | 137 | }); | ||
131 | } | 138 | } | ||
132 | 139 | | |||
133 | var mpris = document.querySelectorAll("[data-extension=mpris]")[0]; | | |||
134 | var mprisEx = document.querySelectorAll("[data-extension=mprisMediaSessions]")[0]; | | |||
135 | mpris.addEventListener("change", function() { | | |||
136 | mprisEx.disabled = !mpris.checked; | | |||
137 | }); | | |||
138 | mprisEx.disabled = !mpris.checked; | | |||
139 | | ||||
140 | // check whether the platform is supported before loading and activating settings | 140 | // check whether the platform is supported before loading and activating settings | ||
141 | chrome.runtime.getPlatformInfo(function (info) { | 141 | chrome.runtime.getPlatformInfo(function (info) { | ||
142 | if (!SUPPORTED_PLATFORMS.includes(info.os)) { | 142 | if (!SUPPORTED_PLATFORMS.includes(info.os)) { | ||
143 | document.body.classList.add("not-supported"); | 143 | document.body.classList.add("not-supported"); | ||
144 | return; | 144 | return; | ||
145 | } | 145 | } | ||
146 | 146 | | |||
147 | loadSettings(); | 147 | loadSettings(function () { | ||
148 | var mpris = document.querySelector("[data-extension=mpris]"); | ||||
149 | var mprisEx = document.querySelector("[data-extension=mprisMediaSessions]"); | ||||
150 | mpris.addEventListener("change", function() { | ||||
151 | mprisEx.disabled = !mpris.checked; | ||||
152 | }); | ||||
153 | mprisEx.disabled = !mpris.checked; | ||||
154 | }); | ||||
148 | 155 | | |||
149 | // auto save when changing any setting | 156 | // auto save when changing any setting | ||
150 | // TODO can we do that on closing, or does it not matter how often we do chrome storage sync thing? | 157 | // TODO can we do that on closing, or does it not matter how often we do chrome storage sync thing? | ||
151 | document.querySelectorAll("input[type=checkbox]").forEach(function (item) { | 158 | document.querySelectorAll("input[type=checkbox]").forEach(function (item) { | ||
152 | item.addEventListener("click", function () { | 159 | item.addEventListener("click", function () { | ||
153 | var saveMessage = document.getElementById("save-message"); | 160 | var saveMessage = document.getElementById("save-message"); | ||
154 | saveMessage.innerText = ""; | 161 | saveMessage.innerText = ""; | ||
155 | 162 | | |||
Show All 32 Lines |