aboutsummaryrefslogtreecommitdiffstats
path: root/background_page.html
diff options
context:
space:
mode:
Diffstat (limited to 'background_page.html')
-rw-r--r--background_page.html35
1 files changed, 31 insertions, 4 deletions
diff --git a/background_page.html b/background_page.html
index d8f28df4..bd032bcd 100644
--- a/background_page.html
+++ b/background_page.html
@@ -10,6 +10,8 @@
var portHandlers = { "keyDown": handleKeyDown,
"returnScrollPosition": handleReturnScrollPosition,
"getCurrentTabUrl": getCurrentTabUrl,
+ "getZoomLevel": getZoomLevel,
+ "saveZoomLevel": saveZoomLevel,
"getSetting": getSetting};
// Event handlers
@@ -47,31 +49,56 @@
* because window.location doesn't know anything about the Chrome-specific "view-source:".
*/
function getCurrentTabUrl(args) {
- chrome.tabs.getSelected(null, function (tab) {
+ chrome.tabs.getSelected(null, function(tab) {
var returnPort = chrome.tabs.connect(tab.id, { name: "returnCurrentTabUrl" });
returnPort.postMessage({ url: tab.url });
});
}
/*
+ * Returns the previously saved zoom level for the current tab, or the default zoom level
+ */
+ function getZoomLevel(args) {
+ chrome.tabs.getSelected(null, function(tab) {
+ var returnPort = chrome.tabs.connect(tab.id, { name: "returnZoomLevel" });
+ var localStorageKey = "zoom" + args.domain;
+ var zoomLevelForDomain = (localStorage[localStorageKey] || "").split(",")[1];
+ var zoomLevel = parseInt(zoomLevelForDomain || localStorage["defaultZoomLevel"] || 100);
+ returnPort.postMessage({ zoomLevel: zoomLevel });
+ });
+ }
+
+ /*
* Used by the content scripts to get settings from the local storage.
*/
function getSetting(args) {
var value = localStorage[args.key] ? localStorage[args.key] : defaultSettings[args.key];
- chrome.tabs.getSelected(null, function (tab) {
+ chrome.tabs.getSelected(null, function(tab) {
var returnPort = chrome.tabs.connect(tab.id, { name: "returnSetting" });
returnPort.postMessage({ key: args.key, value: value });
});
}
- chrome.tabs.onSelectionChanged.addListener(function (tabId, selectionInfo) {
+ /*
+ * Persists the current zoom level for a given domain
+ */
+ function saveZoomLevel(args) {
+ var localStorageKey = "zoom" + args.domain;
+ // TODO(philc): We might want to consider expiring these entries after X months as NoSquint does.
+ // Note(philc): We might also want to jsonify this hash instead of polluting our local storage keyspace.
+ localStorage[localStorageKey] = [getCurrentTimeInSeconds(), args.zoomLevel].join(",");
+ }
+
+ function getCurrentTimeInSeconds() { Math.floor((new Date()).getTime() / 1000); }
+
+ chrome.tabs.onSelectionChanged.addListener(function(tabId, selectionInfo) {
if (selectionChangedHandlers.length > 0) { selectionChangedHandlers.pop().call(); }
});
function repeatFunction(func, totalCount, currentCount) {
if (currentCount < totalCount)
- func(function () { repeatFunction(func, totalCount, currentCount + 1); });
+ func(function() { repeatFunction(func, totalCount, currentCount + 1); });
}
// Returns the currently selected tab along with scroll coordinates. Pass in a callback of the form: