1
0
mirror of https://github.com/gorhill/uBlock.git synced 2024-09-15 15:32:28 +02:00

Handle picture > source elements

Related issue:
- https://github.com/uBlockOrigin/uBlock-issues/issues/2069
This commit is contained in:
Raymond Hill 2022-03-28 12:11:18 -04:00
parent ab6a59daf8
commit 3391435f75
No known key found for this signature in database
GPG Key ID: 25E1490B761470C2

View File

@ -231,13 +231,12 @@ const resourceURLsFromElement = function(elem) {
if ( url !== '' ) { urls.push(url); } if ( url !== '' ) { urls.push(url); }
return urls; return urls;
} }
{ const s = elem[prop];
const s = elem[prop]; if ( typeof s === 'string' && /^https?:\/\//.test(s) ) {
if ( typeof s === 'string' && /^https?:\/\//.test(s) ) { urls.push(trimFragmentFromURL(s.slice(0, 1024)));
urls.push(trimFragmentFromURL(s.slice(0, 1024)));
}
} }
resourceURLsFromSrcset(elem, urls); resourceURLsFromSrcset(elem, urls);
resourceURLsFromPicture(elem, urls);
return urls; return urls;
}; };
@ -272,6 +271,20 @@ const resourceURLsFromSrcset = function(elem, out) {
} }
}; };
// https://github.com/uBlockOrigin/uBlock-issues/issues/2069#issuecomment-1080600661
// https://developer.mozilla.org/en-US/docs/Web/HTML/Element/picture
const resourceURLsFromPicture = function(elem, out) {
if ( elem.localName === 'source' ) { return; }
const picture = elem.parentElement;
if ( picture === null || picture.localName !== 'picture' ) { return; }
const sources = picture.querySelectorAll(':scope > source');
for ( const source of sources ) {
const urls = resourceURLsFromElement(source);
if ( urls.length === 0 ) { continue; }
out.push(...urls);
}
};
/******************************************************************************/ /******************************************************************************/
const netFilterFromUnion = function(patternIn, out) { const netFilterFromUnion = function(patternIn, out) {
@ -364,6 +377,7 @@ const netFilter1stSources = {
'iframe': 'src', 'iframe': 'src',
'img': 'src', 'img': 'src',
'object': 'data', 'object': 'data',
'source': 'src',
'video': 'src' 'video': 'src'
}; };