Merge reused code into a common file
Change-Id: I264aaa67ae1103df2292e17d1eb46b3054799994
diff --git a/src/background.js b/src/background.js
index 6728e07..688aaa1 100644
--- a/src/background.js
+++ b/src/background.js
@@ -1,45 +1,9 @@
-function isEmpty(obj) {
- return Object.keys(obj).length === 0;
-}
-
-const defaultOptions = {
- 'list': true,
- 'thread': true,
- 'threadall': false,
- 'fixedtoolbar': false,
- 'redirect': false,
- 'history': false,
- 'loaddrafts': false,
- 'batchduplicate': false,
- 'escalatethreads': false,
- 'movethreads': false,
- 'increasecontrast': false,
- 'stickysidebarheaders': false,
- 'profileindicator': false,
-};
-
-function cleanUpOptions() {
- chrome.storage.sync.get(null, function(options) {
- console.log('[cleanUpOptions] Previous options', options);
- var ok = true;
- for (const [opt, value] of Object.entries(defaultOptions)) {
- if (!(opt in options)) {
- ok = false;
- options[opt] = value;
- }
- }
-
- console.log('[cleanUpOptions] New options', options);
-
- if (!ok) {
- chrome.storage.sync.set(options);
- }
- });
-}
-
+// When the extension gets updated, set new options to their default value.
chrome.runtime.onInstalled.addListener(function(details) {
if (details.reason == 'install' || details.reason == 'update') {
- cleanUpOptions();
+ chrome.storage.sync.get(null, function(options) {
+ cleanUpOptions(options);
+ });
}
});