summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Gläßer <tobimensch@users.noreply.github.com>2018-10-29 10:35:22 -0400
committerThomas Buckley-Houston <tom@tombh.co.uk>2019-06-24 09:09:58 +0300
commitd3fff67c61b67ac2f0924818da8c1fdc3c45fabc (patch)
tree897de2ae5f39b08962222407d3fdc393da462151
parentbd5c30640db90c7f926d5703dee1844d5869ea9b (diff)
Prettified js files
-rw-r--r--webext/src/background/tty_commands_mixin.js10
-rw-r--r--webext/src/vimium.js1686
2 files changed, 1060 insertions, 636 deletions
diff --git a/webext/src/background/tty_commands_mixin.js b/webext/src/background/tty_commands_mixin.js
index 815674b..dc33b59 100644
--- a/webext/src/background/tty_commands_mixin.js
+++ b/webext/src/background/tty_commands_mixin.js
@@ -186,16 +186,16 @@ export default MixinBase =>
}
restoreTab() {
- var sessionsInfo = browser.sessions.getRecentlyClosed({maxResults: 1 });
+ var sessionsInfo = browser.sessions.getRecentlyClosed({ maxResults: 1 });
sessionsInfo.then(this._restoreTab);
}
-
+
_restoreTab(sessionsInfo) {
var mySessionInfo = sessionsInfo[0];
if (mySessionInfo.tab) {
- browser.sessions.restore(mySessionInfo.tab.sessionId);
- } else {
- browser.sessions.restore(mySessionInfo.window.sessionId);
+ browser.sessions.restore(mySessionInfo.tab.sessionId);
+ } else {
+ browser.sessions.restore(mySessionInfo.window.sessionId);
}
}
diff --git a/webext/src/vimium.js b/webext/src/vimium.js
index 6463294..246c535 100644
--- a/webext/src/vimium.js
+++ b/webext/src/vimium.js
@@ -6,7 +6,7 @@
// to better fullfill the needs of Browsh:
//
// In line 11 of getLocalHints the following code was added:
-//
+//
// if (requireHref && element.href && visibleElement.length > 0) {
// visibleElement[0]["href"] = element.href;
// }
@@ -27,7 +27,7 @@
// The following lines just before the return statement in getLocalHints were
// commented out, because we're currently not using this functionality and the
// settings for it simply don't exist in Browsh (yet).
-//
+//
// /*if (Settings.get("filterLinkHints")) {
// for (m = 0, len3 = localHints.length; m < len3; m++) {
// hint = localHints[m];
@@ -39,81 +39,114 @@
// because Browsh is currently assuming that it is being run in Firefox.
var Rect = {
- create: function(x1, y1, x2, y2) {
- return {
- bottom: y2,
- top: y1,
- left: x1,
- right: x2,
- width: x2 - x1,
- height: y2 - y1
- };
- },
- copy: function(rect) {
- return {
- bottom: rect.bottom,
- top: rect.top,
- left: rect.left,
- right: rect.right,
- width: rect.width,
- height: rect.height
- };
- },
- translate: function(rect, x, y) {
- if (x == null) {
- x = 0;
- }
- if (y == null) {
- y = 0;
- }
- return {
- bottom: rect.bottom + y,
- top: rect.top + y,
- left: rect.left + x,
- right: rect.right + x,
- width: rect.width,
- height: rect.height
+ create: function(x1, y1, x2, y2) {
+ return {
+ bottom: y2,
+ top: y1,
+ left: x1,
+ right: x2,
+ width: x2 - x1,
+ height: y2 - y1
};
- },
- subtract: function(rect1, rect2) {
- var rects;
- rect2 = this.create(Math.max(rect1.left, rect2.left), Math.max(rect1.top, rect2.top), Math.min(rect1.right, rect2.right), Math.min(rect1.bottom, rect2.bottom));
- if (rect2.width < 0 || rect2.height < 0) {
- return [Rect.copy(rect1)];
- }
- rects = [this.create(rect1.left, rect1.top, rect2.left, rect2.top), this.create(rect2.left, rect1.top, rect2.right, rect2.top), this.create(rect2.right, rect1.top, rect1.right, rect2.top), this.create(rect1.left, rect2.top, rect2.left, rect2.bottom), this.create(rect2.right, rect2.top, rect1.right, rect2.bottom), this.create(rect1.left, rect2.bottom, rect2.left, rect1.bottom), this.create(rect2.left, rect2.bottom, rect2.right, rect1.bottom), this.create(rect2.right, rect2.bottom, rect1.right, rect1.bottom)];
- return rects.filter(function(rect) {
- return rect.height > 0 && rect.width > 0;
- });
- },
- intersects: function(rect1, rect2) {
- return rect1.right > rect2.left && rect1.left < rect2.right && rect1.bottom > rect2.top && rect1.top < rect2.bottom;
- },
- intersectsStrict: function(rect1, rect2) {
- return rect1.right >= rect2.left && rect1.left <= rect2.right && rect1.bottom >= rect2.top && rect1.top <= rect2.bottom;
- },
- equals: function(rect1, rect2) {
- var i, len, property, ref;
- ref = ["top", "bottom", "left", "right", "width", "height"];
- for (i = 0, len = ref.length; i < len; i++) {
- property = ref[i];
- if (rect1[property] !== rect2[property]) {
- return false;
- }
+ },
+ copy: function(rect) {
+ return {
+ bottom: rect.bottom,
+ top: rect.top,
+ left: rect.left,
+ right: rect.right,
+ width: rect.width,
+ height: rect.height
+ };
+ },
+ translate: function(rect, x, y) {
+ if (x == null) {
+ x = 0;
+ }
+ if (y == null) {
+ y = 0;
+ }
+ return {
+ bottom: rect.bottom + y,
+ top: rect.top + y,
+ left: rect.left + x,
+ right: rect.right + x,
+ width: rect.width,
+ height: rect.height
+ };
+ },
+ subtract: function(rect1, rect2) {
+ var rects;
+ rect2 = this.create(
+ Math.max(rect1.left, rect2.left),
+ Math.max(rect1.top, rect2.top),
+ Math.min(rect1.right, rect2.right),
+ Math.min(rect1.bottom, rect2.bottom)
+ );
+ if (rect2.width < 0 || rect2.height < 0) {
+ return [Rect.copy(rect1)];
+ }
+ rects = [
+ this.create(rect1.left, rect1.top, rect2.left, rect2.top),
+ this.create(rect2.left, rect1.top, rect2.right, rect2.top),
+ this.create(rect2.right, rect1.top, rect1.right, rect2.top),
+ this.create(rect1.left, rect2.top, rect2.left, rect2.bottom),
+ this.create(rect2.right, rect2.top, rect1.right, rect2.bottom),
+ this.create(rect1.left, rect2.bottom, rect2.left, rect1.bottom),
+ this.create(rect2.left, rect2.bottom, rect2.right, rect1.bottom),
+ this.create(rect2.right, rect2.bottom, rect1.right, rect1.bottom)
+ ];
+ return rects.filter(function(rect) {
+ return rect.height > 0 && rect.width > 0;
+ });
+ },
+ intersects: function(rect1, rect2) {
+ return (
+ rect1.right > rect2.left &&
+ rect1.left < rect2.right &&
+ rect1.bottom > rect2.top &&
+ rect1.top < rect2.bottom
+ );
+ },
+ intersectsStrict: function(rect1, rect2) {
+ return (
+ rect1.right >= rect2.left &&
+ rect1.left <= rect2.right &&
+ rect1.bottom >= rect2.top &&
+ rect1.top <= rect2.bottom
+ );
+ },
+ equals: function(rect1, rect2) {
+ var i, len, property, ref;
+ ref = ["top", "bottom", "left", "right", "width", "height"];
+ for (i = 0, len = ref.length; i < len; i++) {
+ property = ref[i];
+ if (rect1[property] !== rect2[property]) {
+ return false;
}
- return true;
- },
- intersect: function(rect1, rect2) {
- return this.create(Math.max(rect1.left, rect2.left), Math.max(rect1.top, rect2.top), Math.min(rect1.right, rect2.right), Math.min(rect1.bottom, rect2.bottom));
}
- };
+ return true;
+ },
+ intersect: function(rect1, rect2) {
+ return this.create(
+ Math.max(rect1.left, rect2.left),
+ Math.max(rect1.top, rect2.top),
+ Math.min(rect1.right, rect2.right),
+ Math.min(rect1.bottom, rect2.bottom)
+ );
+ }
+};
var DomUtils = {
- documentReady: function() {
- var callbacks, isReady, onDOMContentLoaded, ref;
- ref = [document.readyState !== "loading", []], isReady = ref[0], callbacks = ref[1];
- if (!isReady) {
- window.addEventListener("DOMContentLoaded", onDOMContentLoaded = forTrusted(function() {
+ documentReady: function() {
+ var callbacks, isReady, onDOMContentLoaded, ref;
+ (ref = [document.readyState !== "loading", []]),
+ (isReady = ref[0]),
+ (callbacks = ref[1]);
+ if (!isReady) {
+ window.addEventListener(
+ "DOMContentLoaded",
+ (onDOMContentLoaded = forTrusted(function() {
var callback, i, len;
window.removeEventListener("DOMContentLoaded", onDOMContentLoaded);
isReady = true;
@@ -121,408 +154,696 @@ var DomUtils = {
callback = callbacks[i];
callback();
}
- return callbacks = null;
- }));
+ return (callbacks = null);
+ }))
+ );
+ }
+ return function(callback) {
+ if (isReady) {
+ return callback();
+ } else {
+ return callbacks.push(callback);
}
- return function(callback) {
- if (isReady) {
- return callback();
- } else {
- return callbacks.push(callback);
- }
- };
- },
- getVisibleClientRect: function(element, testChildren) {
- var child, childClientRect, clientRect, clientRects, computedStyle, i, isInlineZeroHeight, j, len, len1, ref, ref1;
- if (testChildren == null) {
- testChildren = false;
+ };
+ },
+ getVisibleClientRect: function(element, testChildren) {
+ var child,
+ childClientRect,
+ clientRect,
+ clientRects,
+ computedStyle,
+ i,
+ isInlineZeroHeight,
+ j,
+ len,
+ len1,
+ ref,
+ ref1;
+ if (testChildren == null) {
+ testChildren = false;
+ }
+ clientRects = (function() {
+ var i, len, ref, results;
+ ref = element.getClientRects();
+ results = [];
+ for (i = 0, len = ref.length; i < len; i++) {
+ clientRect = ref[i];
+ results.push(Rect.copy(clientRect));
}
- clientRects = (function() {
- var i, len, ref, results;
- ref = element.getClientRects();
- results = [];
- for (i = 0, len = ref.length; i < len; i++) {
- clientRect = ref[i];
- results.push(Rect.copy(clientRect));
- }
- return results;
- })();
+ return results;
+ })();
+ isInlineZeroHeight = function() {
+ var elementComputedStyle, isInlineZeroFontSize;
+ elementComputedStyle = window.getComputedStyle(element, null);
+ isInlineZeroFontSize =
+ 0 ===
+ elementComputedStyle.getPropertyValue("display").indexOf("inline") &&
+ elementComputedStyle.getPropertyValue("font-size") === "0px";
isInlineZeroHeight = function() {
- var elementComputedStyle, isInlineZeroFontSize;
- elementComputedStyle = window.getComputedStyle(element, null);
- isInlineZeroFontSize = (0 === elementComputedStyle.getPropertyValue("display").indexOf("inline")) && (elementComputedStyle.getPropertyValue("font-size") === "0px");
- isInlineZeroHeight = function() {
- return isInlineZeroFontSize;
- };
return isInlineZeroFontSize;
};
- for (i = 0, len = clientRects.length; i < len; i++) {
- clientRect = clientRects[i];
- if ((clientRect.width === 0 || clientRect.height === 0) && testChildren) {
- ref = element.children;
- for (j = 0, len1 = ref.length; j < len1; j++) {
- child = ref[j];
- computedStyle = window.getComputedStyle(child, null);
- if (computedStyle.getPropertyValue("float") === "none" && !((ref1 = computedStyle.getPropertyValue("position")) === "absolute" || ref1 === "fixed") && !(clientRect.height === 0 && isInlineZeroHeight() && 0 === computedStyle.getPropertyValue("display").indexOf("inline"))) {
- continue;
- }
- childClientRect = this.getVisibleClientRect(child, true);
- if (childClientRect === null || childClientRect.width < 3 || childClientRect.height < 3) {
- continue;
- }
- return childClientRect;
- }
- } else {
- clientRect = this.cropRectToVisible(clientRect);
- if (clientRect === null || clientRect.width < 3 || clientRect.height < 3) {
+ return isInlineZeroFontSize;
+ };
+ for (i = 0, len = clientRects.length; i < len; i++) {
+ clientRect = clientRects[i];
+ if ((clientRect.width === 0 || clientRect.height === 0) && testChildren) {
+ ref = element.children;
+ for (j = 0, len1 = ref.length; j < len1; j++) {
+ child = ref[j];
+ computedStyle = window.getComputedStyle(child, null);
+ if (
+ computedStyle.getPropertyValue("float") === "none" &&
+ !(
+ (ref1 = computedStyle.getPropertyValue("position")) ===
+ "absolute" || ref1 === "fixed"
+ ) &&
+ !(
+ clientRect.height === 0 &&
+ isInlineZeroHeight() &&
+ 0 === computedStyle.getPropertyValue("display").indexOf("inline")
+ )
+ ) {
continue;
}
- computedStyle = window.getComputedStyle(element, null);
- if (computedStyle.getPropertyValue('visibility') !== 'visible') {
+ childClientRect = this.getVisibleClientRect(child, true);
+ if (
+ childClientRect === null ||
+ childClientRect.width < 3 ||
+ childClientRect.height < 3
+ ) {
continue;
}
- return clientRect;
+ return childClientRect;
}
+ } else {
+ clientRect = this.cropRectToVisible(clientRect);
+ if (
+ clientRect === null ||
+ clientRect.width < 3 ||
+ clientRect.height < 3
+ ) {
+ continue;
+ }
+ computedStyle = window.getComputedStyle(element, null);
+ if (computedStyle.getPropertyValue("visibility") !== "visible") {
+ continue;
+ }
+ return clientRect;
}
+ }
+ return null;
+ },
+ cropRectToVisible: function(rect) {
+ var boundedRect;
+ boundedRect = Rect.create(
+ Math.max(rect.left, 0),
+ Math.max(rect.top, 0),
+ rect.right,
+ rect.bottom
+ );
+ if (
+ boundedRect.top >= window.innerHeight - 4 ||
+ boundedRect.left >= window.innerWidth - 4
+ ) {
return null;
- },
- cropRectToVisible: function(rect) {
- var boundedRect;
- boundedRect = Rect.create(Math.max(rect.left, 0), Math.max(rect.top, 0), rect.right, rect.bottom);
- if (boundedRect.top >= window.innerHeight - 4 || boundedRect.left >= window.innerWidth - 4) {
- return null;
+ } else {
+ return boundedRect;
+ }
+ },
+ getClientRectsForAreas: function(imgClientRect, areas) {
+ var area,
+ coords,
+ diff,
+ i,
+ len,
+ r,
+ rect,
+ rects,
+ ref,
+ shape,
+ x,
+ x1,
+ x2,
+ y,
+ y1,
+ y2;
+ rects = [];
+ for (i = 0, len = areas.length; i < len; i++) {
+ area = areas[i];
+ coords = area.coords.split(",").map(function(coord) {
+ return parseInt(coord, 10);
+ });
+ shape = area.shape.toLowerCase();
+ if (shape === "rect" || shape === "rectangle") {
+ (x1 = coords[0]), (y1 = coords[1]), (x2 = coords[2]), (y2 = coords[3]);
+ } else if (shape === "circle" || shape === "circ") {
+ (x = coords[0]), (y = coords[1]), (r = coords[2]);
+ diff = r / Math.sqrt(2);
+ x1 = x - diff;
+ x2 = x + diff;
+ y1 = y - diff;
+ y2 = y + diff;
+ } else if (shape === "default") {
+ (ref = [0, 0, imgClientRect.width, imgClientRect.height]),
+ (x1 = ref[0]),
+ (y1 = ref[1]),
+ (x2 = ref[2]),
+ (y2 = ref[3]);
} else {
- return boundedRect;
+ (x1 = coords[0]), (y1 = coords[1]), (x2 = coords[2]), (y2 = coords[3]);
}
- },
- getClientRectsForAreas: function(imgClientRect, areas) {
- var area, coords, diff, i, len, r, rect, rects, ref, shape, x, x1, x2, y, y1, y2;
- rects = [];
- for (i = 0, len = areas.length; i < len; i++) {
- area = areas[i];
- coords = area.coords.split(",").map(function(coord) {
- return parseInt(coord, 10);
+ rect = Rect.translate(
+ Rect.create(x1, y1, x2, y2),
+ imgClientRect.left,
+ imgClientRect.top
+ );
+ rect = this.cropRectToVisible(rect);
+ if (rect && !isNaN(rect.top)) {
+ rects.push({
+ element: area,
+ rect: rect
});
- shape = area.shape.toLowerCase();
- if (shape === "rect" || shape === "rectangle") {
- x1 = coords[0], y1 = coords[1], x2 = coords[2], y2 = coords[3];
- } else if (shape === "circle" || shape === "circ") {
- x = coords[0], y = coords[1], r = coords[2];
- diff = r / Math.sqrt(2);
- x1 = x - diff;
- x2 = x + diff;
- y1 = y - diff;
- y2 = y + diff;
- } else if (shape === "default") {
- ref = [0, 0, imgClientRect.width, imgClientRect.height], x1 = ref[0], y1 = ref[1], x2 = ref[2], y2 = ref[3];
- } else {
- x1 = coords[0], y1 = coords[1], x2 = coords[2], y2 = coords[3];
- }
- rect = Rect.translate(Rect.create(x1, y1, x2, y2), imgClientRect.left, imgClientRect.top);
- rect = this.cropRectToVisible(rect);
- if (rect && !isNaN(rect.top)) {
- rects.push({
- element: area,
- rect: rect
- });
- }
}
- return rects;
- },
- isSelectable: function(element) {
- var unselectableTypes;
- if (!(element instanceof Element)) {
- return false;
+ }
+ return rects;
+ },
+ isSelectable: function(element) {
+ var unselectableTypes;
+ if (!(element instanceof Element)) {
+ return false;
+ }
+ unselectableTypes = [
+ "button",
+ "checkbox",
+ "color",
+ "file",
+ "hidden",
+ "image",
+ "radio",
+ "reset",
+ "submit"
+ ];
+ return (
+ (element.nodeName.toLowerCase() === "input" &&
+ unselectableTypes.indexOf(element.type) === -1) ||
+ element.nodeName.toLowerCase() === "textarea" ||
+ element.isContentEditable
+ );
+ },
+ getViewportTopLeft: function() {
+ var box, clientLeft, clientTop, marginLeft, marginTop, rect, style;
+ box = document.documentElement;
+ style = getComputedStyle(box);
+ rect = box.getBoundingClientRect();
+ if (
+ style.position === "static" &&
+ !/content|paint|strict/.test(style.contain || "")
+ ) {
+ marginTop = parseInt(style.marginTop);
+ marginLeft = parseInt(style.marginLeft);
+ return {
+ top: -rect.top + marginTop,
+ left: -rect.left + marginLeft
+ };
+ } else {
+ //if (Utils.isFirefox())
+ if (true) {
+ clientTop = parseInt(style.borderTopWidth);
+ clientLeft = parseInt(style.borderLeftWidth);
+ } else {
+ (clientTop = box.clientTop), (clientLeft = box.clientLeft);
}
- unselectableTypes = ["button", "checkbox", "color", "file", "hidden", "image", "radio", "reset", "submit"];
- return (element.nodeName.toLowerCase() === "input" && unselectableTypes.indexOf(element.type) === -1) || element.nodeName.toLowerCase() === "textarea" || element.isContentEditable;
- },
- getViewportTopLeft: function() {
- var box, clientLeft, clientTop, marginLeft, marginTop, rect, style;
- box = document.documentElement;
- style = getComputedStyle(box);
- rect = box.getBoundingClientRect();
- if (style.position === "static" && !/content|paint|strict/.test(style.contain || "")) {
- marginTop = parseInt(style.marginTop);
- marginLeft = parseInt(style.marginLeft);
- return {
- top: -rect.top + marginTop,
- left: -rect.left + marginLeft
- };
+ return {
+ top: -rect.top - clientTop,
+ left: -rect.left - clientLeft
+ };
+ }
+ },
+ makeXPath: function(elementArray) {
+ var element, i, len, xpath;
+ xpath = [];
+ for (i = 0, len = elementArray.length; i < len; i++) {
+ element = elementArray[i];
+ xpath.push(".//" + element, ".//xhtml:" + element);
+ }
+ return xpath.join(" | ");
+ },
+ evaluateXPath: function(xpath, resultType) {
+ var contextNode, namespaceResolver;
+ contextNode = document.webkitIsFullScreen
+ ? document.webkitFullscreenElement
+ : document.documentElement;
+ namespaceResolver = function(namespace) {
+ if (namespace === "xhtml") {
+ return "http://www.w3.org/1999/xhtml";
} else {
- //if (Utils.isFirefox())
- if (true) {
- clientTop = parseInt(style.borderTopWidth);
- clientLeft = parseInt(style.borderLeftWidth);
- } else {
- clientTop = box.clientTop, clientLeft = box.clientLeft;
- }
- return {
- top: -rect.top - clientTop,
- left: -rect.left - clientLeft
- };
+ return null;
}
- },
- makeXPath: function(elementArray) {
- var element, i, len, xpath;
- xpath = [];
- for (i = 0, len = elementArray.length; i < len; i++) {
- element = elementArray[i];
- xpath.push(".//" + element, ".//xhtml:" + element);
- }
- return xpath.join(" | ");
- },
- evaluateXPath: function(xpath, resultType) {
- var contextNode, namespaceResolver;
- contextNode = document.webkitIsFullScreen ? document.webkitFullscreenElement : document.documentElement;
- namespaceResolver = function(namespace) {
- if (namespace === "xhtml") {
- return "http://www.w3.org/1999/xhtml";
- } else {
- return null;
- }
- };
- return document.evaluate(xpath, contextNode, namespaceResolver, resultType, null);
- },
- simulateClick: function(element, modifiers) {
- var defaultActionShouldTrigger, event, eventSequence, i, len, results;
- if (modifiers == null) {
- modifiers = {};
- }
- eventSequence = ["mouseover", "mousedown", "mouseup", "click"];
- results = [];
- for (i = 0, len = eventSequence.length; i < len; i++) {
- event = eventSequence[i];
- defaultActionShouldTrigger = /*Utils.isFirefox() &&*/ Object.keys(modifiers).length === 0 && event === "click" && element.target === "_blank" && element.href && !element.hasAttribute("onclick") && !element.hasAttribute("_vimium-has-onclick-listener") ? true : this.simulateMouseEvent(event, element, modifiers);
- if (event === "click" && defaultActionShouldTrigger /*&& Utils.isFirefox()*/) {
- if (0 < Object.keys(modifiers).length || element.target === "_blank") {
- DomUtils.simulateClickDefaultAction(element, modifiers);
- }
- }
- results.push(defaultActionShouldTrigger);
- }
- return results;
- },
- simulateMouseEvent: (function() {
- var lastHoveredElement;
- lastHoveredElement = void 0;
- return function(event, element, modifiers) {
- var mouseEvent;
- if (modifiers == null) {
- modifiers = {};
- }
- if (event === "mouseout") {
- if (element == null) {
- element = lastHoveredElement;
- }
- lastHoveredElement = void 0;
- if (element == null) {
- return;
- }
- } else if (event === "mouseover") {
- this.simulateMouseEvent("mouseout", void 0, modifiers);
- lastHoveredElement = element;
- }
- mouseEvent = document.createEvent("MouseEvents");
- mouseEvent.initMouseEvent(event, true, true, window, 1, 0, 0, 0, 0, modifiers.ctrlKey, modifiers.altKey, modifiers.shiftKey, modifiers.metaKey, 0, null);
- return element.dispatchEvent(mouseEvent);
- };
- })(),
- simulateClickDefaultAction: function(element, modifiers) {
- var altKey, ctrlKey, metaKey, newTabModifier, ref, shiftKey;
- if (modifiers == null) {
- modifiers = {};
- }
- if (!(((ref = element.tagName) != null ? ref.toLowerCase() : void 0) === "a" && (element.href != null))) {
- return;
- }
- ctrlKey = modifiers.ctrlKey, shiftKey = modifiers.shiftKey, metaKey = modifiers.metaKey, altKey = modifiers.altKey;
- if (KeyboardUtils.platform === "Mac") {
- newTabModifier = metaKey === true && ctrlKey === false;
- } else {
- newTabModifier = metaKey === false && ctrlKey === true;
- }
- if (newTabModifier) {
- chrome.runtime.sendMessage({
- handler: "openUrlInNewTab",
- url: element.href,
- active: shiftKey === true
- });
- } else if (shiftKey === true && metaKey === false && ctrlKey === false && altKey === false) {
- chrome.runtime.sendMessage({
- handler: "openUrlInNewWindow",
- url: element.href
- });
- } else if (element.target === "_blank") {
- chrome.runtime.sendMessage({
- handler: "openUrlInNewTab",
- url: element.href,
- active: true
- });
- }
- }
-}
-
- var LocalHints = {
- getVisibleClickable: function(element) {
- var actionName, areas, areasAndRects, base1, clientRect, contentEditable, eventType, i, imgClientRects, isClickable, jsactionRule, jsactionRules, len, map, mapName, namespace, onlyHasTabIndex, possibleFalsePositive, reason, ref, ref1, ref10, ref11, ref12, ref2, ref3, ref4, ref5, ref6, ref7, ref8, ref9, role, ruleSplit, tabIndex, tabIndexValue, tagName, visibleElements, slice;
- tagName = (ref = typeof (base1 = element.tagName).toLowerCase === "function" ? base1.toLowerCase() : void 0) != null ? ref : "";
- isClickable = false;
- onlyHasTabIndex = false;
- possibleFalsePositive = false;
- visibleElements = [];
- reason = null;
- slice = [].slice;
- if (tagName === "img") {
- mapName = element.getAttribute("usemap");
- if (mapName) {
- imgClientRects = element.getClientRects();
- mapName = mapName.replace(/^#/, "").replace("\"", "\\\"");
- map = document.querySelector("map[name=\"" + mapName + "\"]");
- if (map && imgClientRects.length > 0) {
- areas = map.getElementsByTagName("area");
- areasAndRects = DomUtils.getClientRectsForAreas(imgClientRects[0], areas);
- visibleElements.push.apply(visibleElements, areasAndRects);
- }
+ };
+ return document.evaluate(
+ xpath,
+ contextNode,
+ namespaceResolver,
+ resultType,
+ null
+ );
+ },
+ simulateClick: function(element, modifiers) {
+ var defaultActionShouldTrigger, event, eventSequence, i, len, results;
+ if (modifiers == null) {
+ modifiers = {};
+ }
+ eventSequence = ["mouseover", "mousedown", "mouseup", "click"];
+ results = [];
+ for (i = 0, len = eventSequence.length; i < len; i++) {
+ event = eventSequence[i];
+ defaultActionShouldTrigger =
+ /*Utils.isFirefox() &&*/ Object.keys(modifiers).length === 0 &&
+ event === "click" &&
+ element.target === "_blank" &&
+ element.href &&
+ !element.hasAttribute("onclick") &&
+ !element.hasAttribute("_vimium-has-onclick-listener")
+ ? true
+ : this.simulateMouseEvent(event, element, modifiers);
+ if (
+ event === "click" &&
+ defaultActionShouldTrigger /*&& Utils.isFirefox()*/
+ ) {
+ if (0 < Object.keys(modifiers).length || element.target === "_blank") {
+ DomUtils.simulateClickDefaultAction(element, modifiers);
}
}
- if (((ref1 = (ref2 = element.getAttribute("aria-hidden")) != null ? ref2.toLowerCase() : void 0) === "" || ref1 === "true") || ((ref3 = (ref4 = element.getAttribute("aria-disabled")) != null ? ref4.toLowerCase() : void 0) === "" || ref3 === "true")) {
- return [];
+ results.push(defaultActionShouldTrigger);
+ }
+ return results;
+ },
+ simulateMouseEvent: (function() {
+ var lastHoveredElement;
+ lastHoveredElement = void 0;
+ return function(event, element, modifiers) {
+ var mouseEvent;
+ if (modifiers == null) {
+ modifiers = {};
}
- if (this.checkForAngularJs == null) {
- this.checkForAngularJs = (function() {
- var angularElements, i, k, len, len1, ngAttributes, prefix, ref5, ref6, separator;
- angularElements = document.getElementsByClassName("ng-scope");
- if (angularElements.length === 0) {
- return function() {
- return false;
- };
- } else {
- ngAttributes = [];
- ref5 = ['', 'data-', 'x-'];
- for (i = 0, len = ref5.length; i < len; i++) {
- prefix = ref5[i];
- ref6 = ['-', ':', '_'];
- for (k = 0, len1 = ref6.length; k < len1; k++) {
- separator = ref6[k];
- ngAttributes.push(prefix + "ng" + separator + "click");
- }
- }
- return function(element) {
- var attribute, l, len2;
- for (l = 0, len2 = ngAttributes.length; l < len2; l++) {
- attribute = ngAttributes[l];
- if (element.hasAttribute(attribute)) {
- return true;
- }
- }
- return false;
- };
- }
- })();
+ if (event === "mouseout") {
+ if (element == null) {
+ element = lastHoveredElement;
+ }
+ lastHoveredElement = void 0;
+ if (element == null) {
+ return;
+ }
+ } else if (event === "mouseover") {
+ this.simulateMouseEvent("mouseout", void 0, modifiers);
+ lastHoveredElement = element;
}
- isClickable || (isClickable = this.checkForAngularJs(element));
- if (element.hasAttribute("onclick") || (role = element.getAttribute("role")) && ((ref5 = role.toLowerCase()) === "button" || ref5 === "tab" || ref5 === "link" || ref5 === "checkbox" || ref5 === "menuitem" || ref5 === "menuitemcheckbox" || ref5 === "menuitemradio") || (contentEditable = element.getAttribute("contentEditable")) && ((ref6 = contentEditable.toLowerCase()) === "" || ref6 === "contenteditable" || ref6 === "true")) {
- isClickable = true;
+ mouseEvent = document.createEvent("MouseEvents");
+ mouseEvent.initMouseEvent(
+ event,
+ true,
+ true,
+ window,
+ 1,
+ 0,
+ 0,
+ 0,
+ 0,
+ modifiers.ctrlKey,
+ modifiers.altKey,
+ modifiers.shiftKey,
+ modifiers.metaKey,
+ 0,
+ null
+ );
+ return element.dispatchEvent(mouseEvent);
+ };
+ })(),
+ simulateClickDefaultAction: function(element, modifiers) {
+ var altKey, ctrlKey, metaKey, newTabModifier, ref, shiftKey;
+ if (modifiers == null) {
+ modifiers = {};
+ }
+ if (
+ !(
+ ((ref = element.tagName) != null ? ref.toLowerCase() : void 0) ===
+ "a" && element.href != null
+ )
+ ) {
+ return;
+ }
+ (ctrlKey = modifiers.ctrlKey),
+ (shiftKey = modifiers.shiftKey),
+ (metaKey = modifiers.metaKey),
+ (altKey = modifiers.altKey);
+ if (KeyboardUtils.platform === "Mac") {
+ newTabModifier = metaKey === true && ctrlKey === false;
+ } else {
+ newTabModifier = metaKey === false && ctrlKey === true;
+ }
+ if (newTabModifier) {
+ chrome.runtime.sendMessage({
+ handler: "openUrlInNewTab",
+ url: element.href,
+ active: shiftKey === true
+ });
+ } else if (
+ shiftKey === true &&
+ metaKey === false &&
+ ctrlKey === false &&
+ altKey === false
+ ) {
+ chrome.runtime.sendMessage({
+ handler: "openUrlInNewWindow",
+ url: element.href
+ });
+ } else if (element.target === "_blank") {
+ chrome.runtime.sendMessage({
+ handler: "openUrlInNewTab",
+ url: element.href,
+ active: true
+ });
+ }
+ }
+};
+
+var LocalHints = {
+ getVisibleClickable: function(element) {
+ var actionName,
+ areas,
+ areasAndRects,
+ base1,
+ clientRect,
+ contentEditable,
+ eventType,
+ i,
+ imgClientRects,
+ isClickable,
+ jsactionRule,
+ jsactionRules,
+ len,
+ map,
+ mapName,
+ namespace,
+ onlyHasTabIndex,
+ possibleFalsePositive,
+ reason,
+ ref,
+ ref1,
+ ref10,
+ ref11,
+ ref12,
+ ref2,
+ ref3,
+ ref4,
+ ref5,
+ ref6,
+ ref7,
+ ref8,
+ ref9,
+ role,
+ ruleSplit,
+ tabIndex,
+ tabIndexValue,
+ tagName,
+ visibleElements,
+ slice;
+ tagName =
+ (ref =
+ typeof (base1 = element.tagName).toLowerCase === "function"
+ ? base1.toLowerCase()
+ : void 0) != null
+ ? ref
+ : "";
+ isClickable = false;
+ onlyHasTabIndex = false;
+ possibleFalsePositive = false;
+ visibleElements = [];
+ reason = null;
+ slice = [].slice;
+ if (tagName === "img") {
+ mapName = element.getAttribute("usemap");
+ if (mapName) {
+ imgClientRects = element.getClientRects();
+ mapName = mapName.replace(/^#/, "").replace('"', '\\"');
+ map = document.querySelector('map[name="' + mapName + '"]');
+ if (map && imgClientRects.length > 0) {
+ areas = map.getElementsByTagName("area");
+ areasAndRects = DomUtils.getClientRectsForAreas(
+ imgClientRects[0],
+ areas
+ );
+ visibleElements.push.apply(visibleElements, areasAndRects);
+ }
}
- if (!isClickable && element.hasAttribute("jsaction")) {
- jsactionRules = element.getAttribute("jsaction").split(";");
- for (i = 0, len = jsactionRules.length; i < len; i++) {
- jsactionRule = jsactionRules[i];
- ruleSplit = jsactionRule.trim().split(":");
- if ((1 <= (ref7 = ruleSplit.length) && ref7 <= 2)) {
- ref8 = ruleSplit.length === 1 ? ["click"].concat(slice.call(ruleSplit[0].trim().split(".")), ["_"]) : [ruleSplit[0]].concat(slice.call(ruleSplit[1].trim().split(".")), ["_"]), eventType = ref8[0], namespace = ref8[1], actionName = ref8[2];
- isClickable || (isClickable = eventType === "click" && namespace !== "none" && actionName !== "_");
+ }
+ if (
+ (ref1 =
+ (ref2 = element.getAttribute("aria-hidden")) != null
+ ? ref2.toLowerCase()
+ : void 0) === "" ||
+ ref1 === "true" ||
+