this fixes part of #671

This commit is contained in:
gorhill 2015-02-03 18:43:51 -05:00
parent bbb2d8d1ff
commit a9e9ea454f
1 changed files with 13 additions and 9 deletions

View File

@ -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);
}
}