Skip to content

Commit

Permalink
Make EAF Browser vimium more accurate, filter overlapping links
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewZMD committed Jan 31, 2020
1 parent 981d33d commit e17a961
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
5 changes: 4 additions & 1 deletion core/browser.py
Expand Up @@ -258,9 +258,12 @@ def open_link_new_buffer(self):
def jump_to_link(self, marker, new_buffer=False):
self.goto_marker_js = self.goto_marker_raw.replace("%1", str(marker));
link = self.web_page.executeJavaScript(self.goto_marker_js)
self.cleanup_links()
if link != "":
self.open_url(link, new_buffer)
self.cleanup_links()
else:
self.message_to_emacs.emit("Marker incorrect, cannot jump to link.")


def get_focus_text(self):
return self.web_page.executeJavaScript(self.get_focus_text_js)
Expand Down
10 changes: 9 additions & 1 deletion core/js/get_markers.js
Expand Up @@ -35,6 +35,11 @@
rect[2] != 0 && rect[3] != 0);
}

function isElementOnTop(element, rect){
let topElement = document.elementFromPoint(rect[1], rect[0]);
return element.isSameNode(topElement) || element.contains(topElement);
}

function hasCopy(validRects, rect){
for(let i = 0; i < validRects.length; i++) {
let each = validRects[i];
Expand All @@ -49,7 +54,9 @@
let rect;
for(let i = 0; i < elements.length; i++) {
rect = getCoords(elements[i]);
if(isElementOnScreen(rect) && !hasCopy(validRects, rect)){
if(isElementOnScreen(rect)
&& isElementOnTop(elements[i], rect)
&& !hasCopy(validRects, rect)){
validRects.push(rect);
}
}
Expand Down Expand Up @@ -87,6 +94,7 @@
addElementToRects(validRects, document.querySelectorAll('button')); // collect buttons
addElementToRects(validRects, document.querySelectorAll('[aria-haspopup]')); // collect menu buttons
addElementToRects(validRects, document.querySelectorAll('[role="button"]')); // collect role="button"
addElementToRects(validRects, document.querySelectorAll('textarea')); // collect textarea

let body = document.querySelector('body');
let markerContainer = document.createElement('div');
Expand Down
10 changes: 6 additions & 4 deletions core/js/goto_marker.js
Expand Up @@ -11,12 +11,12 @@
if(match != undefined){
let selector = match.getAttribute('pointed-link');
let link = document.querySelector(selector);
if(link.href != undefined && link.href != ''){
if(link.href != undefined && link.href != '' && link.getAttribute('href') != ''){
return link.href;
}else if((link.nodeName.toLowerCase() === 'button') || // normal button
(link.hasAttribute('aria-haspopup')) || // menu button
(link.getAttribute('role') === 'button') || // role="button" buttons
(link.getAttribute('href') === '')){ // special href case that's button
(link.hasAttribute('aria-haspopup')) || // menu button
(link.getAttribute('role') === 'button') || // role="button" buttons
(link.getAttribute('href') === '')){ // special href case that's button
link.click();
} else if(link.nodeName.toLowerCase() === 'input'){
if(link.getAttribute('type') === 'submit'){
Expand All @@ -27,6 +27,8 @@
link.focus();
link.select();
}
} else if(link.nodeName.toLowerCase() === 'textarea'){
link.focus();
}
}
return "";
Expand Down

0 comments on commit e17a961

Please sign in to comment.