aboutsummaryrefslogtreecommitdiffstats
path: root/background_page.html
diff options
context:
space:
mode:
Diffstat (limited to 'background_page.html')
-rw-r--r--background_page.html137
1 files changed, 80 insertions, 57 deletions
diff --git a/background_page.html b/background_page.html
index 2be1e7b2..7d8f749d 100644
--- a/background_page.html
+++ b/background_page.html
@@ -25,15 +25,23 @@
var defaultSettings = {
scrollStepSize: 60,
- defaultZoomLevel: 100,
linkHintCharacters: "sadfjklewcmpgh",
+ filterLinkHints: false,
userDefinedLinkHintCss:
".vimiumHintMarker {\n\n}\n" +
".vimiumHintMarker > .matchingCharacter {\n\n}",
excludedUrls: "http*://mail.google.com/*\n" +
"http*://www.google.com/reader/*\n",
- previousPatterns: "\\bprev\\b,\\bprevious\\b,\\u00AB,<<,<",
- nextPatterns: "\\bnext\\b,\\u00BB,>>,\\bmore\\b,>"
+
+ // 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,>>",
};
// This is the base internal link hints CSS. It's combined with the userDefinedLinkHintCss before
@@ -65,13 +73,12 @@
keyDown: handleKeyDown,
returnScrollPosition: handleReturnScrollPosition,
getCurrentTabUrl: getCurrentTabUrl,
- getZoomLevel: getZoomLevel,
- saveZoomLevel: saveZoomLevel,
- getSetting: getSetting
+ getSetting: getSetting,
+ getBookmarks: getBookmarks
};
var sendRequestHandlers = {
- getCompletionKeys: getCompletionKeys,
+ getCompletionKeys: getCompletionKeysRequest,
getLinkHintCss: getLinkHintCss,
openUrlInNewTab: openUrlInNewTab,
openUrlInCurrentTab: openUrlInCurrentTab,
@@ -81,6 +88,7 @@
upgradeNotificationClosed: upgradeNotificationClosed,
updateScrollPosition: handleUpdateScrollPosition,
copyToClipboard: copyToClipboard,
+ copyLinkUrl: copyLinkUrl,
isEnabledForUrl: isEnabledForUrl,
saveHelpDialogSettings: saveHelpDialogSettings
};
@@ -158,17 +166,6 @@
localStorage["helpDialog_showAdvancedCommands"] = request.showAdvancedCommands;
}
- /*
- * Returns the previously saved zoom level for the current tab, or the default zoom level
- */
- function getZoomLevel(args, port) {
- 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 || getSettingFromLocalStorage("defaultZoomLevel"));
- returnPort.postMessage({ zoomLevel: zoomLevel });
- }
-
function showHelp(callback, frameId) {
chrome.tabs.getSelected(null, function(tab) {
chrome.tabs.sendRequest(tab.id,
@@ -236,8 +233,11 @@
/**
* Returns the keys that can complete a valid command given the current key queue.
*/
- function getCompletionKeys(request) {
- return {completionKeys: generateCompletionKeys()};
+ function getCompletionKeysRequest(request) {
+ return { name: "refreshCompletionKeys",
+ completionKeys: generateCompletionKeys(),
+ validFirstKeys: validFirstKeys
+ };
}
/**
@@ -258,6 +258,14 @@
chrome.tabs.create({ url: request.url, index: tab.index + 1, selected: request.selected });
});
}
+
+ /**
+ * Copies url of selected link to the clipboard (wget ftw)
+ */
+ function copyLinkUrl(request) {
+ Clipboard.copy(request.data);
+ }
+
/*
* Returns the core CSS used for link hints, along with any user-provided overrides.
*/
@@ -290,6 +298,12 @@
returnPort.postMessage({ key: args.key, value: value });
}
+ function getBookmarks(args, port) {
+ chrome.bookmarks.search(args.query, function(bookmarks) {
+ port.postMessage({bookmarks:bookmarks})
+ })
+ }
+
/*
* Used by everyone to get settings from local storage.
*/
@@ -301,16 +315,6 @@
}
}
- /*
- * 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) {
@@ -337,23 +341,34 @@
function nextTab(callback) { selectTab(callback, "next"); }
function previousTab(callback) { selectTab(callback, "previous"); }
+ function firstTab(callback) { selectTab(callback, "first"); }
+ function lastTab(callback) { selectTab(callback, "last"); }
/*
- * Selects a tab before or after the currently selected tab. Direction is either "next" or "previous".
+ * Selects a tab before or after the currently selected tab. Direction is either "next", "previous", "first" or "last".
*/
function selectTab(callback, direction) {
chrome.tabs.getAllInWindow(null, function(tabs) {
if (tabs.length <= 1)
return;
- for (var i = 0; i < tabs.length; i++) {
- if (tabs[i].selected) {
- var delta = (direction == "next") ? 1 : -1;
- var toSelect = tabs[(i + delta + tabs.length) % tabs.length];
+ chrome.tabs.getSelected(null, function(currentTab) {
+ switch (direction) {
+ case "next":
+ toSelect = tabs[(currentTab.index + 1 + tabs.length) % tabs.length];
+ break;
+ case "previous":
+ toSelect = tabs[(currentTab.index - 1 + tabs.length) % tabs.length];
+ break;
+ case "first":
+ toSelect = tabs[0];
+ break;
+ case "last":
+ toSelect = tabs[tabs.length - 1];
+ break;
+ }
selectionChangedHandlers.push(callback);
chrome.tabs.update(toSelect.id, { selected: true });
- break;
- }
- }
+ });
});
}
@@ -368,6 +383,8 @@
function updateOpenTabs(tab) {
openTabs[tab.id] = { url: tab.url, positionIndex: tab.index, windowId: tab.windowId };
+ // Frames are recreated on refresh
+ delete framesForTab[tab.id];
}
function handleUpdateScrollPosition(request, sender) {
@@ -502,7 +519,7 @@
populateValidFirstKeys();
populateSingleKeyCommands();
- sendRequestToAllTabs({ name: "refreshCompletionKeys", completionKeys: generateCompletionKeys() });
+ sendRequestToAllTabs(getCompletionKeysRequest());
}
/*
@@ -574,7 +591,11 @@
refreshedCompletionKeys = true;
} else {
- repeatFunction(this[registryEntry.command], count, 0, frameId);
+ if(registryEntry.passCountToFunction){
+ this[registryEntry.command](count);
+ } else {
+ repeatFunction(this[registryEntry.command], count, 0, frameId);
+ }
}
newKeyQueue = "";
@@ -592,10 +613,8 @@
// If we haven't sent the completion keys piggybacked on executePageCommand,
// send them by themselves.
- if (!refreshedCompletionKeys)
- {
- var port = chrome.tabs.connect(tabId, { name: "refreshCompletionKeys" });
- port.postMessage({ completionKeys: generateCompletionKeys(newKeyQueue) });
+ if (!refreshedCompletionKeys) {
+ chrome.tabs.sendRequest(tabId, getCompletionKeysRequest(), null);
}
return newKeyQueue;
@@ -648,7 +667,7 @@
if (!framesForTab[sender.tab.id])
framesForTab[sender.tab.id] = { frames: [] };
- if (request.top) {
+ if (request.is_top) {
focusedFrame = request.frameId;
framesForTab[sender.tab.id].total = request.total;
}
@@ -681,25 +700,29 @@
focusedFrame = request.frameId;
}
- function nextFrame(callback, frameId) {
+ function nextFrame(count) {
chrome.tabs.getSelected(null, function(tab) {
- var index;
var frames = framesForTab[tab.id].frames;
+ var curr_index = getCurrFrameIndex(frames);
- for (index=0; index < frames.length; index++) {
- if (frames[index].id == focusedFrame)
- break;
- }
-
- if (index >= frames.length-1)
- index = 0;
- else
- index++;
+ // TODO: Skip the "top" frame (which doesn't actually have a <frame> tag),
+ // since it exists only to contain the other frames.
+ var new_index = (curr_index + count) % frames.length;
- chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[index].id, highlight: true });
+ chrome.tabs.sendRequest(tab.id, { name: "focusFrame", frameId: frames[new_index].id, highlight: true });
});
}
+ function getCurrFrameIndex(frames) {
+ var index;
+ for (index=0; index < frames.length; index++) {
+ if (frames[index].id == focusedFrame)
+ break;
+ }
+ return index;
+ }
+
+
function init() {
clearKeyMappingsAndSetDefaults();