mirror of https://github.com/gorhill/uBlock.git
this fixes #290
This commit is contained in:
parent
13d229eaa1
commit
f26e332098
|
@ -107,12 +107,15 @@ var uBlockCollapser = (function() {
|
|||
var newRequests = [];
|
||||
var pendingRequests = {};
|
||||
var pendingRequestCount = 0;
|
||||
var srcProps = {
|
||||
var src1stProps = {
|
||||
'embed': 'src',
|
||||
'iframe': 'src',
|
||||
'img': 'src',
|
||||
'object': 'data'
|
||||
};
|
||||
var src2ndProps = {
|
||||
'img': 'srcset'
|
||||
};
|
||||
|
||||
var PendingRequest = function(target, tagName, attr) {
|
||||
this.id = requestId++;
|
||||
|
@ -215,15 +218,22 @@ var uBlockCollapser = (function() {
|
|||
|
||||
var add = function(target) {
|
||||
var tagName = target.localName;
|
||||
var prop = srcProps[tagName];
|
||||
var prop = src1stProps[tagName];
|
||||
if ( prop === undefined ) {
|
||||
return;
|
||||
}
|
||||
// https://github.com/chrisaljoudi/uBlock/issues/174
|
||||
// Do not remove fragment from src URL
|
||||
var src = target[prop];
|
||||
if ( typeof src !== 'string' || src === '' ) {
|
||||
return;
|
||||
if ( typeof src !== 'string' || src.length === 0 ) {
|
||||
prop = src2ndProps[tagName];
|
||||
if ( prop === undefined ) {
|
||||
return;
|
||||
}
|
||||
src = target[prop];
|
||||
if ( typeof src !== 'string' || src.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if ( src.lastIndexOf('http', 0) !== 0 ) {
|
||||
return;
|
||||
|
|
|
@ -318,12 +318,15 @@ var netFilterFromElement = function(elem, out) {
|
|||
return;
|
||||
}
|
||||
var tagName = elem.tagName.toLowerCase();
|
||||
if ( netFilterSources.hasOwnProperty(tagName) === false ) {
|
||||
if ( netFilter1stSources.hasOwnProperty(tagName) === false ) {
|
||||
return;
|
||||
}
|
||||
var src = elem[netFilterSources[tagName]];
|
||||
if ( src.length === 0 ) {
|
||||
return;
|
||||
var src = elem[netFilter1stSources[tagName]];
|
||||
if ( typeof src !== 'string' || src.length === 0 ) {
|
||||
src = elem[netFilter2ndSources[tagName]];
|
||||
if ( typeof src !== 'string' || src.length === 0 ) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Remove fragment
|
||||
var pos = src.indexOf('#');
|
||||
|
@ -346,13 +349,17 @@ var netFilterFromElement = function(elem, out) {
|
|||
netFilterFromUnion(src, out);
|
||||
};
|
||||
|
||||
var netFilterSources = {
|
||||
var netFilter1stSources = {
|
||||
'embed': 'src',
|
||||
'iframe': 'src',
|
||||
'img': 'src',
|
||||
'object': 'data'
|
||||
};
|
||||
|
||||
var netFilter2ndSources = {
|
||||
'img': 'srcset'
|
||||
};
|
||||
|
||||
/******************************************************************************/
|
||||
|
||||
// Extract the best possible cosmetic filter, i.e. as specific as possible.
|
||||
|
@ -529,13 +536,17 @@ var elementsFromFilter = function(filter) {
|
|||
return out;
|
||||
}
|
||||
|
||||
var props = netFilterSources;
|
||||
var elems = document.querySelectorAll(Object.keys(props).join());
|
||||
var src1stProps = netFilter1stSources;
|
||||
var src2ndProps = netFilter2ndSources;
|
||||
var elems = document.querySelectorAll(Object.keys(src1stProps).join());
|
||||
var i = elems.length;
|
||||
var elem, src;
|
||||
while ( i-- ) {
|
||||
elem = elems[i];
|
||||
src = elem[props[elem.tagName.toLowerCase()]];
|
||||
src = elem[src1stProps[elem.localName]];
|
||||
if ( typeof src !== 'string' || src.length === 0 ) {
|
||||
src = elem[src2ndProps[elem.localName]];
|
||||
}
|
||||
if ( src && reFilter.test(src) ) {
|
||||
out.push(elem);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue