aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--background_page.html34
-rw-r--r--background_scripts/settings.coffee67
-rw-r--r--background_scripts/settings.js81
-rw-r--r--options.html2
5 files changed, 86 insertions, 99 deletions
diff --git a/.gitignore b/.gitignore
index 885ef3be..6450172c 100644
--- a/.gitignore
+++ b/.gitignore
@@ -3,3 +3,4 @@ background_scripts/commands.js
tests/completion_test.js
tests/test_helper.js
tests/utils_test.js
+background_scripts/settings.js
diff --git a/background_page.html b/background_page.html
index bf1af077..f3b68d3e 100644
--- a/background_page.html
+++ b/background_page.html
@@ -119,7 +119,7 @@
*/
function isEnabledForUrl(request) {
// excludedUrls are stored as a series of URL expressions separated by newlines.
- var excludedUrls = settings.get("excludedUrls").split("\n");
+ var excludedUrls = Settings.get("excludedUrls").split("\n");
var isEnabled = true;
for (var i = 0; i < excludedUrls.length; i++) {
// The user can add "*" to the URL which means ".*"
@@ -137,9 +137,9 @@
url = trim(url);
if (url === "") { return; }
- var excludedUrls = settings.get("excludedUrls");
+ var excludedUrls = Settings.get("excludedUrls");
excludedUrls += "\n" + url;
- settings.set("excludedUrls", excludedUrls);
+ Settings.set("excludedUrls", excludedUrls);
chrome.tabs.query({ windowId: chrome.windows.WINDOW_ID_CURRENT, active: true }, function(tabs) {
updateActiveState(tabs[0].id);
@@ -147,7 +147,7 @@
}
function saveHelpDialogSettings(request) {
- settings.set("helpDialog_showAdvancedCommands", request.showAdvancedCommands);
+ Settings.set("helpDialog_showAdvancedCommands", request.showAdvancedCommands);
}
function showHelp(callback, frameId) {
@@ -174,7 +174,7 @@
dialogHtml = dialogHtml.replace("{{version}}", currentVersion);
dialogHtml = dialogHtml.replace("{{title}}", customTitle || "Help");
dialogHtml = dialogHtml.replace("{{showAdvancedCommands}}",
- settings.get("helpDialog_showAdvancedCommands"));
+ Settings.get("helpDialog_showAdvancedCommands"));
return dialogHtml;
}
@@ -249,7 +249,7 @@
* Returns the user-provided CSS overrides.
*/
function getLinkHintCss(request) {
- return { linkHintCss: (settings.get("userDefinedLinkHintCss") || "") };
+ return { linkHintCss: (Settings.get("userDefinedLinkHintCss") || "") };
}
/*
@@ -257,7 +257,7 @@
* We should now dismiss that message in all tabs.
*/
function upgradeNotificationClosed(request) {
- settings.set("previousVersion", currentVersion);
+ Settings.set("previousVersion", currentVersion);
sendRequestToAllTabs({ name: "hideUpgradeNotification" });
}
@@ -280,11 +280,11 @@
*/
function handleSettings(args, port) {
if (args.operation == "get") {
- var value = settings.get(args.key);
+ var value = Settings.get(args.key);
port.postMessage({ key: args.key, value: value });
}
else { // operation == "set"
- settings.set(args.key, args.value);
+ Settings.set(args.key, args.value);
}
}
@@ -686,9 +686,9 @@
function shouldShowUpgradeMessage() {
// Avoid showing the upgrade notification when previousVersion is undefined, which is the case for new
// installs.
- if (!settings.get("previousVersion"))
- settings.set("previousVersion", currentVersion);
- return compareVersions(currentVersion, settings.get("previousVersion")) == 1;
+ if (!Settings.get("previousVersion"))
+ Settings.set("previousVersion", currentVersion);
+ return compareVersions(currentVersion, Settings.get("previousVersion")) == 1;
}
function openOptionsPageInNewTab() {
@@ -766,20 +766,20 @@
function init() {
Commands.clearKeyMappingsAndSetDefaults();
- if (settings.has("keyMappings"))
- Commands.parseCustomKeyMappings(settings.get("keyMappings"));
+ if (Settings.has("keyMappings"))
+ Commands.parseCustomKeyMappings(Settings.get("keyMappings"));
// In version 1.22, we changed the mapping for "d" and "u" to be scroll page down/up instead of close
// and restore tab. For existing users, we want to preserve existing behavior for them by adding some
// custom key mappings on their behalf.
- if (settings.get("previousVersion") == "1.21") {
- var customKeyMappings = settings.get("keyMappings") || "";
+ if (Settings.get("previousVersion") == "1.21") {
+ var customKeyMappings = Settings.get("keyMappings") || "";
if ((Commands.keyToCommandRegistry["d"] || {}).command == "scrollPageDown")
customKeyMappings += "\nmap d removeTab";
if ((Commands.keyToCommandRegistry["u"] || {}).command == "scrollPageUp")
customKeyMappings += "\nmap u restoreTab";
if (customKeyMappings != "") {
- settings.set("keyMappings", customKeyMappings);
+ Settings.set("keyMappings", customKeyMappings);
Commands.parseCustomKeyMappings(customKeyMappings);
}
}
diff --git a/background_scripts/settings.coffee b/background_scripts/settings.coffee
new file mode 100644
index 00000000..ba9d1831
--- /dev/null
+++ b/background_scripts/settings.coffee
@@ -0,0 +1,67 @@
+#
+# Used by everyone to manipulate localStorage.
+#
+Settings =
+ defaults:
+ scrollStepSize: 60
+ linkHintCharacters: "sadfjklewcmpgh"
+ filterLinkHints: false
+ hideHud: false
+ userDefinedLinkHintCss:
+ "div > .vimiumHintMarker {" + "\n" +
+ "/* linkhint boxes */ " + "\n" +
+ "background-color: yellow;" + "\n" +
+ "border: 1px solid #E3BE23;" + "\n" +
+ "}" + "\n\n" +
+ "div > .vimiumHintMarker span {" + "\n" +
+ "/* linkhint text */ " + "\n" +
+ "color: black;" + "\n" +
+ "font-weight: bold;" + "\n" +
+ "font-size: 12px;" + "\n" +
+ "}" + "\n\n" +
+ "div > .vimiumHintMarker > .matchingCharacter {" + "\n" +
+ "}"
+ excludedUrls: "http*://mail.google.com/*\n" +
+ "http*://www.google.com/reader/*\n"
+
+ # NOTE : If a page contains both a single angle-bracket link and a double angle-bracket link, then in
+ # most cases the single bracket link will be "prev/next page" and the double bracket link will be
+ # "first/last page", so we put the single bracket first in the pattern string so that it gets searched
+ # for first.
+
+ # "\bprev\b,\bprevious\b,\bback\b,<,←,«,≪,<<"
+ previousPatterns: "prev,previous,back,<,\u2190,\xab,\u226a,<<"
+ # "\bnext\b,\bmore\b,>,→,»,≫,>>"
+ nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>"
+
+ init: ->
+ # settingsVersion was introduced in v1.31, and is used to coordinate data migration. We do not use
+ # previousVersion as it is used to coordinate the display of the upgrade message, and is not updated
+ # early enough when the extension loads.
+ # 1.31 was also the version where we converted all localStorage values to JSON.
+ if (!this.has("settingsVersion"))
+ for key of localStorage
+ # filterLinkHints' checkbox state used to be stored as a string
+ if (key == "filterLinkHints")
+ localStorage[key] = if (localStorage[key] == "true") then true else false
+ else
+ localStorage[key] = JSON.stringify(localStorage[key])
+ this.set("settingsVersion", utils.getCurrentVersion())
+
+ get: (key) ->
+ if (key of localStorage) then JSON.parse(localStorage[key]) else this.defaults[key]
+
+ set: (key, value) ->
+ # don't store the value if it is equal to the default, so we can change the defaults in the future
+ if (value == this.defaults[key])
+ this.clear(key)
+ else
+ localStorage[key] = JSON.stringify(value)
+
+ clear: (key) -> delete localStorage[key]
+
+ has: (key) -> key of localStorage
+
+Settings.init()
+root = exports ? window
+root.Settings = Settings
diff --git a/background_scripts/settings.js b/background_scripts/settings.js
deleted file mode 100644
index a00317b0..00000000
--- a/background_scripts/settings.js
+++ /dev/null
@@ -1,81 +0,0 @@
-/*
- * Used by everyone to manipulate localStorage.
- */
-var settings = {
-
- defaults: {
- scrollStepSize: 60,
- linkHintCharacters: "sadfjklewcmpgh",
- filterLinkHints: false,
- hideHud: false,
- userDefinedLinkHintCss:
- "div > .vimiumHintMarker {" + "\n" +
- "/* linkhint boxes */ " + "\n" +
- "background-color: yellow;" + "\n" +
- "border: 1px solid #E3BE23;" + "\n" +
- "}" + "\n\n" +
- "div > .vimiumHintMarker span {" + "\n" +
- "/* linkhint text */ " + "\n" +
- "color: black;" + "\n" +
- "font-weight: bold;" + "\n" +
- "font-size: 12px;" + "\n" +
- "}" + "\n\n" +
- "div > .vimiumHintMarker > .matchingCharacter {" + "\n" +
- "}",
- excludedUrls: "http*://mail.google.com/*\n" +
- "http*://www.google.com/reader/*\n",
-
- // NOTE : If a page contains both a single angle-bracket link and a double angle-bracket link, then in
- // most cases the single bracket link will be "prev/next page" and the double bracket link will be
- // "first/last page", so we put the single bracket first in the pattern string so that it gets searched
- // for first.
-
- // "\bprev\b,\bprevious\b,\bback\b,<,←,«,≪,<<"
- previousPatterns: "prev,previous,back,<,\u2190,\xab,\u226a,<<",
- // "\bnext\b,\bmore\b,>,→,»,≫,>>"
- nextPatterns: "next,more,>,\u2192,\xbb,\u226b,>>",
- },
-
- init: function() {
- // settingsVersion was introduced in v1.31, and is used to coordinate data migration. We do not use
- // previousVersion as it is used to coordinate the display of the upgrade message, and is not updated
- // early enough when the extension loads.
- // 1.31 was also the version where we converted all localStorage values to JSON.
- if (!this.has("settingsVersion")) {
- for (var key in localStorage) {
- // filterLinkHints' checkbox state used to be stored as a string
- if (key == "filterLinkHints")
- localStorage[key] = localStorage[key] === "true" ? true : false;
- else
- localStorage[key] = JSON.stringify(localStorage[key]);
- }
- this.set("settingsVersion", utils.getCurrentVersion());
- }
- },
-
- get: function(key) {
- if (!(key in localStorage))
- return this.defaults[key];
- else
- return JSON.parse(localStorage[key]);
- },
-
- set: function(key, value) {
- // don't store the value if it is equal to the default, so we can change the defaults in the future
- if (value === this.defaults[key])
- this.clear(key);
- else
- localStorage[key] = JSON.stringify(value);
- },
-
- clear: function(key) {
- delete localStorage[key];
- },
-
- has: function(key) {
- return key in localStorage;
- },
-
-};
-
-settings.init();
diff --git a/options.html b/options.html
index ba97d0ab..f4b17997 100644
--- a/options.html
+++ b/options.html
@@ -86,7 +86,7 @@
<script type="text/javascript">
$ = function(id) { return document.getElementById(id); };
- var bgSettings = chrome.extension.getBackgroundPage().settings;
+ var bgSettings = chrome.extension.getBackgroundPage().Settings;
var editableFields = ["scrollStepSize", "excludedUrls", "linkHintCharacters", "userDefinedLinkHintCss",
"keyMappings", "filterLinkHints", "previousPatterns", "nextPatterns", "hideHud"];