mirror of
https://github.com/gorhill/uBlock.git
synced 2024-09-02 17:19:38 +02:00
Improve handling of srcset-based images in element picker
Related issue: - https://github.com/uBlockOrigin/uBlock-issues/issues/517
This commit is contained in:
parent
b73480b4c5
commit
7652808806
@ -342,7 +342,7 @@ const resourceURLFromElement = function(elem) {
|
|||||||
}
|
}
|
||||||
if ( typeof elem.srcset === 'string' && elem.srcset !== '' ) {
|
if ( typeof elem.srcset === 'string' && elem.srcset !== '' ) {
|
||||||
const ss = [];
|
const ss = [];
|
||||||
for ( let s of elem.srcset.split(/\s*,\s+/) ) {
|
for ( let s of elem.srcset.split(',') ) {
|
||||||
const pos = s.indexOf(' ');
|
const pos = s.indexOf(' ');
|
||||||
if ( pos !== -1 ) { s = s.slice(0, pos); }
|
if ( pos !== -1 ) { s = s.slice(0, pos); }
|
||||||
const parsedURL = new URL(s, document.baseURI);
|
const parsedURL = new URL(s, document.baseURI);
|
||||||
@ -471,10 +471,6 @@ const netFilter1stSources = {
|
|||||||
'video': 'src'
|
'video': 'src'
|
||||||
};
|
};
|
||||||
|
|
||||||
const netFilter2ndSources = {
|
|
||||||
'img': 'srcset'
|
|
||||||
};
|
|
||||||
|
|
||||||
const filterTypes = {
|
const filterTypes = {
|
||||||
'audio': 'media',
|
'audio': 'media',
|
||||||
'embed': 'object',
|
'embed': 'object',
|
||||||
@ -750,8 +746,13 @@ const filterToDOMInterface = (function() {
|
|||||||
let srcProp = netFilter1stSources[elem.localName];
|
let srcProp = netFilter1stSources[elem.localName];
|
||||||
let src = elem[srcProp];
|
let src = elem[srcProp];
|
||||||
if ( typeof src !== 'string' || src.length === 0 ) {
|
if ( typeof src !== 'string' || src.length === 0 ) {
|
||||||
srcProp = netFilter2ndSources[elem.localName];
|
if (
|
||||||
src = elem[srcProp];
|
typeof elem.srcset === 'string' &&
|
||||||
|
elem.srcset !== '' &&
|
||||||
|
typeof elem.currentSrc === 'string'
|
||||||
|
) {
|
||||||
|
src = elem.currentSrc;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if ( src && reFilter.test(src) ) {
|
if ( src && reFilter.test(src) ) {
|
||||||
out.push({
|
out.push({
|
||||||
|
Loading…
Reference in New Issue
Block a user