Updated highlighting algorithm
This commit is contained in:
parent
9a0cbd385a
commit
9e6f625e9f
|
@ -1,10 +1,3 @@
|
||||||
function doInCurrentTab(tabCallback) {
|
|
||||||
chrome.tabs.query(
|
|
||||||
{ currentWindow: true, active: true },
|
|
||||||
function (tabArray) { tabCallback(tabArray[0]); }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
chrome.commands.onCommand.addListener(function(command) {
|
chrome.commands.onCommand.addListener(function(command) {
|
||||||
if (command === "start") {
|
if (command === "start") {
|
||||||
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
|
chrome.tabs.query({active: true, currentWindow: true}, function(tabs){
|
||||||
|
|
37
keyhinter.js
37
keyhinter.js
|
@ -1,12 +1,31 @@
|
||||||
var isVisible = function(node) {
|
// Checks if the provided child is descendant of the parent (any level)
|
||||||
// From: http://stackoverflow.com/questions/123999/how-to-tell-if-a-dom-element-is-visible-in-the-current-viewport/7557433#7557433
|
function is_descendant(parent, child) {
|
||||||
var rect = node.getBoundingClientRect();
|
var node = child.parentNode;
|
||||||
return (
|
while (node !== null) {
|
||||||
rect.top >= 0 &&
|
console.log(node)
|
||||||
rect.left >= 0 &&
|
if (node === parent) return true;
|
||||||
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
|
node = node.parentNode;
|
||||||
rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
|
}
|
||||||
);
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
function isVisible(element) {
|
||||||
|
// Element is obviously not visible
|
||||||
|
if (element.offsetWidth === 0 || element.offsetHeight === 0) return false;
|
||||||
|
let rect = element.getClientRects()[0];
|
||||||
|
if (!rect) return false;
|
||||||
|
|
||||||
|
// Get the element clicked in the center of the element rect
|
||||||
|
var element_in_position = document.elementFromPoint((rect.left + rect.right) / 2, (rect.top + rect.bottom) / 2);
|
||||||
|
|
||||||
|
// If there's no result, assume not visible
|
||||||
|
if (!element_in_position) return false;
|
||||||
|
|
||||||
|
// If the element clicked is the same as provided, the element is clearly visible
|
||||||
|
if (element_in_position === element) return true;
|
||||||
|
|
||||||
|
// If the element is not in the position we clicked, check if it's at least a child node
|
||||||
|
return is_descendant(element, element_in_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
class KeyHinter {
|
class KeyHinter {
|
||||||
|
|
Loading…
Reference in New Issue