aboutsummaryrefslogtreecommitdiffstats
path: root/vimiumFrontend.js
diff options
context:
space:
mode:
authorJez Ng2012-01-26 09:31:14 -0500
committerJez Ng2012-01-26 13:21:05 -0500
commitad981199cbb0d3542550713f7658a1726c0c8b24 (patch)
tree5430bbbfe832a03dfc8705d70b6875b89496fc86 /vimiumFrontend.js
parent10d7078eef52514ecf972ea53e1ad1a0646dca68 (diff)
downloadvimium-ad981199cbb0d3542550713f7658a1726c0c8b24.tar.bz2
Next / prev links should be visible.
Also, links later in the document are more likely to be the ones we want as they are further down the page, so favor the former.
Diffstat (limited to 'vimiumFrontend.js')
-rw-r--r--vimiumFrontend.js21
1 files changed, 16 insertions, 5 deletions
diff --git a/vimiumFrontend.js b/vimiumFrontend.js
index d70c2009..1a46a58a 100644
--- a/vimiumFrontend.js
+++ b/vimiumFrontend.js
@@ -877,11 +877,9 @@ function getLinkFromSelection() {
// used by the findAndFollow* functions.
function followLink(link) {
- domUtils.simulateClick(link);
- // blur the element just in case it already has focus. then when we re-focus it, the browser will scroll
- // such that it is visible.
- link.blur();
+ link.scrollIntoView();
link.focus();
+ domUtils.simulateClick(link);
}
/**
@@ -896,8 +894,20 @@ function findAndFollowLink(linkStrings) {
var shortestLinks = [];
var shortestLinkLength = null;
- for (var i = 0, count = links.snapshotLength; i < count; i++) {
+ // at the end of this loop, shortestLinks will be populated with a list of candidates
+ // links lower in the page are more likely to be the ones we want, so we loop through the snapshot backwards
+ for (var i = links.snapshotLength - 1; i >= 0; i--) {
var link = links.snapshotItem(i);
+
+ // ensure link is visible (we don't mind if it is scrolled offscreen)
+ var boundingClientRect = link.getBoundingClientRect();
+ if (boundingClientRect.width == 0 || boundingClientRect.height == 0)
+ continue;
+ var computedStyle = window.getComputedStyle(link, null);
+ if (computedStyle.getPropertyValue('visibility') != 'visible' ||
+ computedStyle.getPropertyValue('display') == 'none')
+ continue;
+
var linkMatches = false;
for (var j = 0; j < linkStrings.length; j++) {
if (link.innerText.toLowerCase().indexOf(linkStrings[j]) !== -1) {
@@ -917,6 +927,7 @@ function findAndFollowLink(linkStrings) {
}
}
+ // try to get exact word matches first
for (var i = 0; i < linkStrings.length; i++)
for (var j = 0; j < shortestLinks.length; j++) {
var exactWordRegex = new RegExp("\\b" + linkStrings[i] + "\\b", "i");