1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-11-07 03:12:33 +01:00
This commit is contained in:
gorhill 2015-06-04 11:17:02 -04:00
parent 13d229eaa1
commit f26e332098
2 changed files with 33 additions and 12 deletions

View File

@ -107,12 +107,15 @@ var uBlockCollapser = (function() {
var newRequests = []; var newRequests = [];
var pendingRequests = {}; var pendingRequests = {};
var pendingRequestCount = 0; var pendingRequestCount = 0;
var srcProps = { var src1stProps = {
'embed': 'src', 'embed': 'src',
'iframe': 'src', 'iframe': 'src',
'img': 'src', 'img': 'src',
'object': 'data' 'object': 'data'
}; };
var src2ndProps = {
'img': 'srcset'
};
var PendingRequest = function(target, tagName, attr) { var PendingRequest = function(target, tagName, attr) {
this.id = requestId++; this.id = requestId++;
@ -215,15 +218,22 @@ var uBlockCollapser = (function() {
var add = function(target) { var add = function(target) {
var tagName = target.localName; var tagName = target.localName;
var prop = srcProps[tagName]; var prop = src1stProps[tagName];
if ( prop === undefined ) { if ( prop === undefined ) {
return; return;
} }
// https://github.com/chrisaljoudi/uBlock/issues/174 // https://github.com/chrisaljoudi/uBlock/issues/174
// Do not remove fragment from src URL // Do not remove fragment from src URL
var src = target[prop]; var src = target[prop];
if ( typeof src !== 'string' || src === '' ) { if ( typeof src !== 'string' || src.length === 0 ) {
return; prop = src2ndProps[tagName];
if ( prop === undefined ) {
return;
}
src = target[prop];
if ( typeof src !== 'string' || src.length === 0 ) {
return;
}
} }
if ( src.lastIndexOf('http', 0) !== 0 ) { if ( src.lastIndexOf('http', 0) !== 0 ) {
return; return;

View File

@ -318,12 +318,15 @@ var netFilterFromElement = function(elem, out) {
return; return;
} }
var tagName = elem.tagName.toLowerCase(); var tagName = elem.tagName.toLowerCase();
if ( netFilterSources.hasOwnProperty(tagName) === false ) { if ( netFilter1stSources.hasOwnProperty(tagName) === false ) {
return; return;
} }
var src = elem[netFilterSources[tagName]]; var src = elem[netFilter1stSources[tagName]];
if ( src.length === 0 ) { if ( typeof src !== 'string' || src.length === 0 ) {
return; src = elem[netFilter2ndSources[tagName]];
if ( typeof src !== 'string' || src.length === 0 ) {
return;
}
} }
// Remove fragment // Remove fragment
var pos = src.indexOf('#'); var pos = src.indexOf('#');
@ -346,13 +349,17 @@ var netFilterFromElement = function(elem, out) {
netFilterFromUnion(src, out); netFilterFromUnion(src, out);
}; };
var netFilterSources = { var netFilter1stSources = {
'embed': 'src', 'embed': 'src',
'iframe': 'src', 'iframe': 'src',
'img': 'src', 'img': 'src',
'object': 'data' 'object': 'data'
}; };
var netFilter2ndSources = {
'img': 'srcset'
};
/******************************************************************************/ /******************************************************************************/
// Extract the best possible cosmetic filter, i.e. as specific as possible. // Extract the best possible cosmetic filter, i.e. as specific as possible.
@ -529,13 +536,17 @@ var elementsFromFilter = function(filter) {
return out; return out;
} }
var props = netFilterSources; var src1stProps = netFilter1stSources;
var elems = document.querySelectorAll(Object.keys(props).join()); var src2ndProps = netFilter2ndSources;
var elems = document.querySelectorAll(Object.keys(src1stProps).join());
var i = elems.length; var i = elems.length;
var elem, src; var elem, src;
while ( i-- ) { while ( i-- ) {
elem = elems[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) ) { if ( src && reFilter.test(src) ) {
out.push(elem); out.push(elem);
} }