| Index: include.postload.js |
| =================================================================== |
| --- a/include.postload.js |
| +++ b/include.postload.js |
| @@ -193,24 +193,6 @@ |
| return getURLsFromAttributes(element); |
| } |
| -function isBlockable(element) |
| -{ |
| - if (element.id) |
| - return true; |
| - if (element.classList.length > 0) |
| - return true; |
| - if (getURLsFromElement(element).length > 0) |
| - return true; |
| - |
| - // We only generate filters based on the "style" attribute, |
| - // if this is the only way we can generate a filter, and |
| - // only if there are at least two CSS properties defined. |
| - if (/:.+:/.test(element.getAttribute("style"))) |
| - return true; |
| - |
| - return false; |
| -} |
| - |
| // Gets the absolute position of an element by walking up the DOM tree, |
| // adding up offsets. |
| // I hope there's a better way because it just seems absolutely stupid |
| @@ -321,13 +303,17 @@ |
| clickHide_deactivate(); |
| // Add overlays for blockable elements that don't emit mouse events that they can still be selected |
| - var elts = document.querySelectorAll('object,embed,iframe'); |
| - for(var i=0; i<elts.length; i++) |
| - { |
| - var element = elts[i]; |
| - if (isBlockable(element)) |
| - addElementOverlay(element); |
| - } |
| + [].forEach.call( |
| + document.querySelectorAll('object,embed,iframe'), |
| + function(element) |
| + { |
| + getFiltersForElement(element, function(filters) |
| + { |
| + if (filters.length > 0) |
| + addElementOverlay(element); |
| + }); |
| + } |
| + ); |
| clickHide_activated = true; |
| document.addEventListener("mouseover", clickHide_mouseOver, true); |
| @@ -388,31 +374,57 @@ |
| clickHide_mouseClick(ev); |
| } |
| +function getBlockableElementOrAncestor(element, callback) |
| +{ |
| + if (element && element != document.documentElement && |
| + element != document.body) |
| + { |
| + if (element instanceof HTMLElement) |
| + { |
| + getFiltersForElement(element, function(filters) |
| + { |
| + if (filters.length > 0) |
| + callback(element); |
| + else |
| + getBlockableElementOrAncestor(element.parentElement, callback); |
| + }); |
| + } |
| + else |
| + { |
| + getBlockableElementOrAncestor(element.parentElement, callback); |
| + } |
| + } |
| + else |
| + { |
| + callback(null); |
| + } |
| +} |
| + |
| // Hovering over an element so highlight it |
| function clickHide_mouseOver(e) |
| { |
| if (clickHide_activated == false) |
| return; |
| - var target = e.target; |
| - while (target.parentNode && !isBlockable(target)) |
| - target = target.parentNode; |
| - if (target == document.documentElement || target == document.body) |
| - target = null; |
| + getBlockableElementOrAncestor(e.target, function(element) |
| + { |
| + if (currentElement) |
| + unhighlightElement(currentElement); |
| - if (target && target instanceof HTMLElement) |
| - { |
| - currentElement = target; |
| + if (element) |
| + { |
| + highlightElement(element, "#d6d84b", "#f8fa47"); |
| + element.addEventListener("contextmenu", clickHide_elementClickHandler, true); |
| + } |
| - highlightElement(target, "#d6d84b", "#f8fa47"); |
| - target.addEventListener("contextmenu", clickHide_elementClickHandler, true); |
| - } |
| + currentElement = element; |
| + }); |
| } |
| // No longer hovering over this element so unhighlight it |
| function clickHide_mouseOut(e) |
| { |
| - if (!clickHide_activated || !currentElement) |
| + if (!clickHide_activated || currentElement != e.target) |
| return; |
| unhighlightElement(currentElement); |
| @@ -450,6 +462,7 @@ |
| style: element.getAttribute("style"), |
| classes: [].slice.call(element.classList), |
| urls: getURLsFromElement(element), |
| + mediatype: typeMap[element.localName], |
| baseURL: document.location.href |
| }, |
| function(response) |