Improve href-sanitizer scriptlet · gorhill/uBlock@84be9cd (original) (raw)
`@@ -3503,17 +3503,26 @@ function hrefSanitizer(
`
3503
3503
`}
`
3504
3504
`return '';
`
3505
3505
`};
`
``
3506
`+
const extractParam = (href, source) => {
`
``
3507
`+
if ( Boolean(source) === false ) { return href; }
`
``
3508
`+
const recursive = source.includes('?', 1);
`
``
3509
`+
const end = recursive ? source.indexOf('?', 1) : source.length;
`
``
3510
`+
try {
`
``
3511
`+
const url = new URL(href, document.location);
`
``
3512
`+
const value = url.searchParams.get(source.slice(1, end));
`
``
3513
`+
if ( value === null ) { return href }
`
``
3514
`+
if ( recursive ) { return extractParam(value, source.slice(end)); }
`
``
3515
`+
return value;
`
``
3516
`+
} catch(x) {
`
``
3517
`+
}
`
``
3518
`+
return href;
`
``
3519
`+
};
`
3506
3520
`const extractText = (elem, source) => {
`
3507
3521
`if ( /^[.*]$/.test(source) ) {
`
3508
3522
`return elem.getAttribute(source.slice(1,-1).trim()) || '';
`
3509
3523
`}
`
3510
3524
`if ( source.startsWith('?') ) {
`
3511
``
`-
try {
`
3512
``
`-
const url = new URL(elem.href, document.location);
`
3513
``
`-
return url.searchParams.get(source.slice(1)) || '';
`
3514
``
`-
} catch(x) {
`
3515
``
`-
}
`
3516
``
`-
return '';
`
``
3525
`+
return extractParam(elem.href, source);
`
3517
3526
`}
`
3518
3527
`if ( source === 'text' ) {
`
3519
3528
`return elem.textContent
`