mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-04 08:37:11 +02:00
In set-attr
, restrict on...
attributes to empty string only
As per feedback from https://github.com/distinctmondaylilac Related commit: https://github.com/gorhill/uBlock/commit/3037ae5f04 Additionally, added logging ability to the scriptlet.
This commit is contained in:
parent
68186a9242
commit
068b625bef
@ -3770,6 +3770,7 @@ builtinScriptlets.push({
|
|||||||
world: 'ISOLATED',
|
world: 'ISOLATED',
|
||||||
dependencies: [
|
dependencies: [
|
||||||
'run-at.fn',
|
'run-at.fn',
|
||||||
|
'safe-self.fn',
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
function setAttr(
|
function setAttr(
|
||||||
@ -3777,9 +3778,11 @@ function setAttr(
|
|||||||
attr = '',
|
attr = '',
|
||||||
value = ''
|
value = ''
|
||||||
) {
|
) {
|
||||||
if ( typeof selector !== 'string' ) { return; }
|
|
||||||
if ( selector === '' ) { return; }
|
if ( selector === '' ) { return; }
|
||||||
|
if ( attr === '' ) { return; }
|
||||||
|
|
||||||
|
const safe = safeSelf();
|
||||||
|
const logPrefix = safe.makeLogPrefix('set-attr', attr, value);
|
||||||
const validValues = [ '', 'false', 'true' ];
|
const validValues = [ '', 'false', 'true' ];
|
||||||
let copyFrom = '';
|
let copyFrom = '';
|
||||||
|
|
||||||
@ -3797,7 +3800,6 @@ function setAttr(
|
|||||||
|
|
||||||
const extractValue = elem => {
|
const extractValue = elem => {
|
||||||
if ( copyFrom !== '' ) {
|
if ( copyFrom !== '' ) {
|
||||||
if ( copyFrom.startsWith('on') && copyFrom in elem ) { return; }
|
|
||||||
return elem.getAttribute(copyFrom) || '';
|
return elem.getAttribute(copyFrom) || '';
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
@ -3814,9 +3816,10 @@ function setAttr(
|
|||||||
for ( const elem of elems ) {
|
for ( const elem of elems ) {
|
||||||
const before = elem.getAttribute(attr);
|
const before = elem.getAttribute(attr);
|
||||||
const after = extractValue(elem);
|
const after = extractValue(elem);
|
||||||
if ( after === undefined ) { continue; }
|
|
||||||
if ( after === before ) { continue; }
|
if ( after === before ) { continue; }
|
||||||
|
if ( attr.startsWith('on') && attr in elem && after !== '' ) { continue; }
|
||||||
elem.setAttribute(attr, after);
|
elem.setAttribute(attr, after);
|
||||||
|
safe.uboLog(logPrefix, `${attr}="${after}"`);
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user