aboutsummaryrefslogtreecommitdiffstats
path: root/background_page.html
diff options
context:
space:
mode:
Diffstat (limited to 'background_page.html')
-rw-r--r--background_page.html36
1 files changed, 27 insertions, 9 deletions
diff --git a/background_page.html b/background_page.html
index abb91677..5b055dbb 100644
--- a/background_page.html
+++ b/background_page.html
@@ -18,8 +18,9 @@
var focusedFrame = null;
var framesForTab = {};
- // Keys are either literal characters, or "named" - for example <a-b> (alt+b), <left> (the left arrow) or <f12>
- // This regular expression captures two groups, the first is a named key, the second is the remainder of the string.
+ // Keys are either literal characters, or "named" - for example <a-b> (alt+b), <left> (left arrow) or <f12>
+ // This regular expression captures two groups: the first is a named key, the second is the remainder of
+ // the string.
var namedKeyRegex = /^(<(?:[amc]-.|(?:[amc]-)?[a-z0-9]{2,5})>)(.*)$/;
var defaultSettings = {
@@ -79,7 +80,8 @@
upgradeNotificationClosed: upgradeNotificationClosed,
updateScrollPosition: handleUpdateScrollPosition,
copyToClipboard: copyToClipboard,
- isEnabledForUrl: isEnabledForUrl
+ isEnabledForUrl: isEnabledForUrl,
+ saveHelpDialogSettings: saveHelpDialogSettings
};
// Event handlers
@@ -140,7 +142,7 @@
*/
function isEnabledForUrl(request) {
// excludedUrls are stored as a series of URL expressions separated by newlines.
- var excludedUrls = (localStorage["excludedUrls"] || defaultSettings.excludedUrls).split("\n");
+ var excludedUrls = getSettingFromLocalStorage("excludedUrls").split("\n");
var isEnabled = true;
for (var i = 0; i < excludedUrls.length; i++) {
// The user can add "*" to the URL which means ".*"
@@ -151,6 +153,10 @@
return { isEnabledForUrl: isEnabled };
}
+ function saveHelpDialogSettings(request) {
+ localStorage["helpDialog_showAdvancedCommands"] = request.showAdvancedCommands;
+ }
+
/*
* Returns the previously saved zoom level for the current tab, or the default zoom level
*/
@@ -158,14 +164,14 @@
var returnPort = chrome.tabs.connect(port.tab.id, { name: "returnZoomLevel" });
var localStorageKey = "zoom" + args.domain;
var zoomLevelForDomain = (localStorage[localStorageKey] || "").split(",")[1];
- var zoomLevel = parseInt(zoomLevelForDomain || localStorage["defaultZoomLevel"] ||
- defaultSettings.defaultZoomLevel);
+ var zoomLevel = parseInt(zoomLevelForDomain || getSettingFromLocalStorage("defaultZoomLevel"));
returnPort.postMessage({ zoomLevel: zoomLevel });
}
function showHelp(callback, frameId) {
chrome.tabs.getSelected(null, function(tab) {
- chrome.tabs.sendRequest(tab.id, { name: "showHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId });
+ chrome.tabs.sendRequest(tab.id,
+ { name: "showHelpDialog", dialogHtml: helpDialogHtml(), frameId:frameId });
});
}
@@ -185,6 +191,8 @@
showUnboundCommands, showCommandNames));
dialogHtml = dialogHtml.replace("{{version}}", currentVersion);
dialogHtml = dialogHtml.replace("{{title}}", customTitle || "Help");
+ dialogHtml = dialogHtml.replace("{{showAdvancedCommands}}",
+ localStorage["helpDialog_showAdvancedCommands"] == "true");
return dialogHtml;
}
@@ -276,13 +284,23 @@
* Used by the content scripts to get settings from the local storage.
*/
function getSetting(args, port) {
- var value = localStorage[args.key] ? localStorage[args.key] : defaultSettings[args.key];
-
+ var value = getSettingFromLocalStorage(args.key);
var returnPort = chrome.tabs.connect(port.tab.id, { name: "returnSetting" });
returnPort.postMessage({ key: args.key, value: value });
}
/*
+ * Used by everyone to get settings from local storage.
+ */
+ function getSettingFromLocalStorage(setting) {
+ if (localStorage[setting] != "" && !localStorage[setting]) {
+ return defaultSettings[setting];
+ } else {
+ return localStorage[setting];
+ }
+ }
+
+ /*
* Persists the current zoom level for a given domain
*/
function saveZoomLevel(args) {