avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 1 | function isEmpty(obj) { |
| 2 | return Object.keys(obj).length === 0; |
| 3 | } |
| 4 | |
| 5 | function save() { |
| 6 | chrome.storage.sync.set({ |
| 7 | "list": document.querySelector("#list").checked, |
| 8 | "thread": document.querySelector("#thread").checked |
| 9 | }, function() { |
| 10 | window.close(); |
| 11 | }); |
| 12 | } |
| 13 | |
| 14 | window.addEventListener("load", function() { |
| 15 | chrome.storage.sync.get(null, function(items) { |
| 16 | if (isEmpty(items)) { |
| 17 | items = {"list": true, "thread": true}; |
| 18 | chrome.storage.sync.set(items); |
| 19 | } |
| 20 | |
| 21 | if (items.list === true) { |
| 22 | document.querySelector("#list").checked = true; |
| 23 | } |
| 24 | |
| 25 | if (items.thread === true) { |
| 26 | document.querySelector("#thread").checked = true; |
| 27 | } |
| 28 | |
| 29 | document.querySelector("#save").addEventListener("click", save); |
| 30 | }); |
| 31 | }); |