From a9e9ea454fbfe1ddf56bc03c6552047382ec1da9 Mon Sep 17 00:00:00 2001 From: gorhill Date: Tue, 3 Feb 2015 18:43:51 -0500 Subject: [PATCH] this fixes part of #671 --- src/js/element-picker.js | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/js/element-picker.js b/src/js/element-picker.js index db79f6173..7915aea4f 100644 --- a/src/js/element-picker.js +++ b/src/js/element-picker.js @@ -114,9 +114,6 @@ /******************************************************************************/ /******************************************************************************/ -/******************************************************************************/ -/******************************************************************************/ - (function() { 'use strict'; @@ -270,10 +267,10 @@ var netFilterFromElement = function(elem, out) { return; } var tagName = elem.tagName.toLowerCase(); - if ( tagName !== 'img' && tagName !== 'iframe' ) { + if ( netFilterSources.hasOwnProperty(tagName) === false ) { return; } - var src = elem.getAttribute('src'); + var src = elem.getAttribute(netFilterSources[tagName]); if ( typeof src !== 'string' || src.length === 0 ) { return; } @@ -297,6 +294,12 @@ var netFilterFromElement = function(elem, out) { } }; +var netFilterSources = { + 'iframe': 'src', + 'img': 'src', + 'object': 'data' +}; + /******************************************************************************/ // Extract the best possible cosmetic filter, i.e. as specific as possible. @@ -431,15 +434,16 @@ var elementsFromFilter = function(filter) { if ( filter.slice(0, 2) === '||' ) { filter = filter.replace('||', ''); } - var elems = document.querySelectorAll('[src]'); + var elems = document.querySelectorAll('iframe,img,object'); var i = elems.length; - var elem; + var elem, src; while ( i-- ) { elem = elems[i]; - if ( typeof elem.src !== 'string' ) { + src = elem.getAttribute(netFilterSources[elem.tagName.toLowerCase()]); + if ( typeof src !== 'string' ) { continue; } - if ( elem.src.indexOf(filter) !== -1 ) { + if ( src.indexOf(filter) !== -1 ) { out.push(elem); } }