Merge reused code into a common file
Change-Id: I264aaa67ae1103df2292e17d1eb46b3054799994
diff --git a/src/common/common.js b/src/common/common.js
new file mode 100644
index 0000000..28c233a
--- /dev/null
+++ b/src/common/common.js
@@ -0,0 +1,44 @@
+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,
+};
+
+const deprecatedOptions = [
+ 'escalatethreads',
+ 'movethreads',
+ 'batchduplicate',
+];
+
+function isEmpty(obj) {
+ return Object.keys(obj).length === 0;
+}
+
+function cleanUpOptions(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);
+ }
+
+ return options;
+}
diff --git a/src/common/content_scripts_injections.js b/src/common/content_scripts_injections.js
new file mode 100644
index 0000000..2067075
--- /dev/null
+++ b/src/common/content_scripts_injections.js
@@ -0,0 +1,16 @@
+function injectStylesheet(stylesheetName) {
+ var link = document.createElement('link');
+ link.setAttribute('rel', 'stylesheet');
+ link.setAttribute('href', stylesheetName);
+ document.head.appendChild(link);
+}
+
+function injectStyles(css) {
+ injectStylesheet('data:text/css;charset=UTF-8,' + encodeURIComponent(css));
+}
+
+function injectScript(scriptName) {
+ var script = document.createElement('script');
+ script.src = scriptName;
+ document.head.appendChild(script);
+}