* This function imports an exported ClearURLs setting and overwrites the old one.
(evt)
| 256 | * This function imports an exported ClearURLs setting and overwrites the old one. |
| 257 | */ |
| 258 | function importSettings(evt) { |
| 259 | let file = evt.target.files[0]; |
| 260 | let fileReader = new FileReader(); |
| 261 | |
| 262 | fileReader.onload = function (e) { |
| 263 | let data = JSON.parse(e.target.result); |
| 264 | const length = Object.keys(data).length; |
| 265 | let i = 0; |
| 266 | |
| 267 | Object.entries(data).forEach(([key, value]) => { |
| 268 | browser.runtime.sendMessage({ |
| 269 | function: "setData", |
| 270 | params: [key, value] |
| 271 | }).then(() => { |
| 272 | i++; |
| 273 | if (i === length) { |
| 274 | location.reload(); |
| 275 | } |
| 276 | }, handleError); |
| 277 | }); |
| 278 | }; |
| 279 | fileReader.readAsText(file); |
| 280 | } |
| 281 | |
| 282 | function handleResponse(message) { |
| 283 | console.log(`Message from the background script: ${message.response}`); |