* Change the value of a switch button. * @param {string} id HTML id * @param {string} storageID storage internal id
(id, storageID)
| 293 | * @param {string} storageID storage internal id |
| 294 | */ |
| 295 | function changeSwitchButton(id, storageID) { |
| 296 | let element = document.getElementById(id); |
| 297 | |
| 298 | element.onchange = function () { |
| 299 | browser.runtime.sendMessage({ |
| 300 | function: "setData", |
| 301 | params: [storageID, element.checked] |
| 302 | }).then(() => { |
| 303 | if (storageID === "globalStatus") { |
| 304 | browser.runtime.sendMessage({ |
| 305 | function: "changeIcon", |
| 306 | params: [] |
| 307 | }).catch(handleError); |
| 308 | } |
| 309 | |
| 310 | browser.runtime.sendMessage({ |
| 311 | function: "saveOnExit", |
| 312 | params: [] |
| 313 | }).catch(handleError); |
| 314 | }).catch(handleError); |
| 315 | }; |
| 316 | setSwitchButton(id, storageID); |
| 317 | } |
| 318 | |
| 319 | /** |
| 320 | * Helper function to inject the translated text and tooltip. |
no test coverage detected