Changeset View
Changeset View
Standalone View
Standalone View
extension/options.js
Show All 37 Lines | 37 | function loadSettings(cb) { | |||
---|---|---|---|---|---|
38 | storage.get(DEFAULT_EXTENSION_SETTINGS, function (items) { | 38 | storage.get(DEFAULT_EXTENSION_SETTINGS, function (items) { | ||
39 | if (chrome.runtime.lastError) { | 39 | if (chrome.runtime.lastError) { | ||
40 | if (typeof cb === "function") { | 40 | if (typeof cb === "function") { | ||
41 | cb(false); | 41 | cb(false); | ||
42 | } | 42 | } | ||
43 | return; | 43 | return; | ||
44 | } | 44 | } | ||
45 | 45 | | |||
46 | for (var key in items) { | 46 | for (let key in items) { | ||
47 | if (!items.hasOwnProperty(key)) { | 47 | if (!items.hasOwnProperty(key)) { | ||
48 | continue; | 48 | continue; | ||
49 | } | 49 | } | ||
50 | 50 | | |||
51 | let controls = document.querySelectorAll("[data-extension=" + key + "]"); | 51 | let controls = document.querySelectorAll("[data-extension=" + key + "]"); | ||
52 | for (let control of controls) { | 52 | for (let control of controls) { | ||
53 | let settingsKey = control.dataset.settingsKey; | 53 | let settingsKey = control.dataset.settingsKey; | ||
54 | if (!settingsKey) { | 54 | if (!settingsKey) { | ||
Show All 10 Lines | 64 | if (value === true) { | |||
65 | control.value = "TRUE"; | 65 | control.value = "TRUE"; | ||
66 | } else if (value === false) { | 66 | } else if (value === false) { | ||
67 | control.value = "FALSE"; | 67 | control.value = "FALSE"; | ||
68 | } else { | 68 | } else { | ||
69 | control.value = value; | 69 | control.value = value; | ||
70 | } | 70 | } | ||
71 | } | 71 | } | ||
72 | 72 | | |||
73 | updateDependencies(control, key, settingsKey); | ||||
74 | | ||||
73 | control.addEventListener("change", () => { | 75 | control.addEventListener("change", () => { | ||
74 | let saveMessage = document.getElementById("save-message"); | 76 | let saveMessage = document.getElementById("save-message"); | ||
75 | saveMessage.innerText = ""; | 77 | saveMessage.innerText = ""; | ||
76 | 78 | | |||
79 | updateDependencies(control, key, settingsKey); | ||||
80 | | ||||
77 | saveSettings((error) => { | 81 | saveSettings((error) => { | ||
78 | if (error) { | 82 | if (error) { | ||
79 | try { | 83 | try { | ||
80 | saveMessage.innerText = chrome.i18n.getMessage("options_save_failed"); | 84 | saveMessage.innerText = chrome.i18n.getMessage("options_save_failed"); | ||
81 | } catch (e) { | 85 | } catch (e) { | ||
82 | // When the extension is reloaded, any call to extension APIs throws, make sure we show at least some form of error | 86 | // When the extension is reloaded, any call to extension APIs throws, make sure we show at least some form of error | ||
83 | saveMessage.innerText = "Saving settings failed (" + (error || e) + ")"; | 87 | saveMessage.innerText = "Saving settings failed (" + (error || e) + ")"; | ||
84 | } | 88 | } | ||
▲ Show 20 Lines • Show All 57 Lines • ▼ Show 20 Line(s) | 145 | storage.set(settings, function () { | |||
142 | return cb(chrome.runtime.lastError); | 146 | return cb(chrome.runtime.lastError); | ||
143 | }); | 147 | }); | ||
144 | // When the extension is reloaded, any call to extension APIs throws | 148 | // When the extension is reloaded, any call to extension APIs throws | ||
145 | } catch (e) { | 149 | } catch (e) { | ||
146 | cb(e); | 150 | cb(e); | ||
147 | } | 151 | } | ||
148 | } | 152 | } | ||
149 | 153 | | |||
154 | function updateDependencies(control, extension, settingsKey) { | ||||
155 | // Update all depending controls | ||||
156 | let value = control.type === "checkbox" ? control.checked : control.value; | ||||
157 | if (value === true) { | ||||
158 | value = "TRUE"; | ||||
159 | } else if (value === false) { | ||||
160 | value = "FALSE"; | ||||
161 | } | ||||
162 | | ||||
163 | let dependencies = document.querySelectorAll("[data-depends-extension=" + extension + "][data-depends-settings-key=" + settingsKey + "]"); | ||||
164 | for (let dependency of dependencies) { | ||||
165 | dependency.disabled = (value != dependency.dataset.dependsSettingsValue); | ||||
166 | } | ||||
167 | } | ||||
168 | | ||||
150 | document.addEventListener("DOMContentLoaded", function () { | 169 | document.addEventListener("DOMContentLoaded", function () { | ||
151 | 170 | | |||
152 | // poor man's tab widget :) | 171 | // poor man's tab widget :) | ||
153 | document.querySelectorAll(".tabbar").forEach(function (tabbar) { | 172 | document.querySelectorAll(".tabbar").forEach(function (tabbar) { | ||
154 | tabbar.buttons = []; | 173 | tabbar.buttons = []; | ||
155 | 174 | | |||
156 | tabbar.querySelectorAll("[data-tab-link]").forEach(function (button) { | 175 | tabbar.querySelectorAll("[data-tab-link]").forEach(function (button) { | ||
157 | 176 | | |||
Show All 23 Lines | |||||
181 | 200 | | |||
182 | // check whether the platform is supported before loading and activating settings | 201 | // check whether the platform is supported before loading and activating settings | ||
183 | chrome.runtime.getPlatformInfo(function (info) { | 202 | chrome.runtime.getPlatformInfo(function (info) { | ||
184 | if (!SUPPORTED_PLATFORMS.includes(info.os)) { | 203 | if (!SUPPORTED_PLATFORMS.includes(info.os)) { | ||
185 | document.body.classList.add("os-not-supported"); | 204 | document.body.classList.add("os-not-supported"); | ||
186 | return; | 205 | return; | ||
187 | } | 206 | } | ||
188 | 207 | | |||
189 | loadSettings(function () { | 208 | loadSettings(); | ||
190 | var mpris = document.querySelector("[data-extension=mpris]"); | | |||
191 | var mprisEx = document.querySelector("[data-extension=mprisMediaSessions]"); | | |||
192 | mpris.addEventListener("change", function() { | | |||
193 | mprisEx.disabled = !mpris.checked; | | |||
194 | }); | | |||
195 | mprisEx.disabled = !mpris.checked; | | |||
196 | }); | | |||
197 | 209 | | |||
198 | // When getSubsystemStatus fails we assume it's an old host without any of the new features | 210 | // When getSubsystemStatus fails we assume it's an old host without any of the new features | ||
199 | // for which we added the requires-extension attributes. Disable all of them initially | 211 | // for which we added the requires-extension attributes. Disable all of them initially | ||
200 | // and then have the supported ones enabled below. | 212 | // and then have the supported ones enabled below. | ||
201 | document.querySelectorAll("[data-requires-extension]").forEach((item) => { | 213 | document.querySelectorAll("[data-requires-extension]").forEach((item) => { | ||
202 | item.classList.add("not-supported", "by-host"); | 214 | item.classList.add("not-supported", "by-host"); | ||
203 | }); | 215 | }); | ||
204 | 216 | | |||
▲ Show 20 Lines • Show All 49 Lines • Show Last 20 Lines |