Fixes #2
diff --git a/background.js b/background.js
index a3aeae1..f8495d6 100644
--- a/background.js
+++ b/background.js
@@ -2,10 +2,32 @@
return Object.keys(obj).length === 0;
}
-chrome.runtime.onInstalled.addListener(function(details) {
- chrome.storage.sync.get(null, function(items) {
- if (isEmpty(items)) {
- chrome.storage.sync.set({"list": true, "thread": true});
+var defaultOptions = {
+ "list": true,
+ "thread": true,
+ "fixedtoolbar": false,
+ "redirect": false,
+ "history": false
+};
+
+function cleanUpOptions() {
+ chrome.storage.sync.get(null, function(options) {
+ var ok = true;
+ for (const [opt, value] of Object.entries(defaultOptions)) {
+ if (!opt in options) {
+ ok = false;
+ options[opt] = value;
+ }
+ }
+
+ if (!ok) {
+ chrome.storage.sync.set(options);
}
});
+}
+
+chrome.runtime.onInstalled.addListener(function(details) {
+ if (details == "install" || details == "update") {
+ cleanUpOptions();
+ }
});
diff --git a/console_inject.js b/console_inject.js
index 2bc6f15..d3dc258 100644
--- a/console_inject.js
+++ b/console_inject.js
@@ -43,4 +43,12 @@
mutationObserver.observe(document.querySelector(".scrollable-content"), observerOptions);
intersectionObserver = new IntersectionObserver(intersectionCallback, intersectionOptions);
+
+ if (options.fixedtoolbar) {
+ var link = document.createElement('link');
+ link.setAttribute("rel", "stylesheet");
+ link.setAttribute("href", "data:text/css;charset=UTF-8,ec-bulk-actions{position: sticky; top: 0; background: white; z-index: 99;}");
+ }
+
+ document.head.appendChild(link);
});
diff --git a/options.html b/options.html
index 48ce91e..655b474 100644
--- a/options.html
+++ b/options.html
@@ -5,8 +5,16 @@
<title>Options</title>
</head>
<body>
- <p><input type="checkbox" id="list"><label for="list"> Enable infinite scrolling in thread lists.</label><br>
- <input type="checkbox" id="thread"><label for="thread"> Enable infinite scrolling inside threads.</label></p>
+ <p>
+ <input type="checkbox" id="list"><label for="list"> Enable infinite scrolling in thread lists.</label><br>
+ <input type="checkbox" id="thread"><label for="thread"> Enable infinite scrolling inside threads.</label>
+ </p>
+ <h4>Additional enhancements</h4>
+ <p>
+ <input type="checkbox" id="fixedtoolbar"><label for="fixedtoolbar"> Fix the toolbar in thread lists in the Community Console.</label><br>
+ <input type="checkbox" id="redirect"><label for="redirect"> Redirect all threads opened in TW to the Community Console. <span style="color: gray;">(doesn't work, in development)</span></label><br>
+ <input type="checkbox" id="history"><label for="history"> Show a "previous posts" link in user profiles. <span style="color: gray;">(doesn't work, in development)</span></label>
+ </p>
<p style="text-align: center;"><button id="save">Save</button></p>
<script src="options.js"></script>
</body>
diff --git a/options.js b/options.js
index d8ce844..48cd864 100644
--- a/options.js
+++ b/options.js
@@ -2,29 +2,49 @@
return Object.keys(obj).length === 0;
}
+var defaultOptions = {
+ "list": true,
+ "thread": true,
+ "fixedtoolbar": false,
+ "redirect": false,
+ "history": false
+};
+
+function cleanUpOptions(options) {
+ var ok = true;
+ for (const [opt, value] of Object.entries(defaultOptions)) {
+ if (!opt in options) {
+ ok = false;
+ options[opt] = value;
+ }
+ }
+
+ if (!ok) {
+ chrome.storage.sync.set(options);
+ }
+}
+
function save() {
- chrome.storage.sync.set({
- "list": document.querySelector("#list").checked,
- "thread": document.querySelector("#thread").checked
- }, function() {
+ var options = defaultOptions;
+
+ Object.keys(options).forEach(function (opt) {
+ options[opt] = document.querySelector("#"+opt).checked;
+ });
+
+ chrome.storage.sync.set(options, function() {
window.close();
});
}
window.addEventListener("load", function() {
chrome.storage.sync.get(null, function(items) {
- if (isEmpty(items)) {
- items = {"list": true, "thread": true};
- chrome.storage.sync.set(items);
- }
+ cleanUpOptions(items);
- if (items.list === true) {
- document.querySelector("#list").checked = true;
- }
-
- if (items.thread === true) {
- document.querySelector("#thread").checked = true;
- }
+ Object.keys(defaultOptions).forEach(function(opt) {
+ if (items[opt] === true) {
+ document.querySelector("#"+opt).checked = true;
+ }
+ });
document.querySelector("#save").addEventListener("click", save);
});