mirror of
https://github.com/gorhill/uBlock.git
synced 2024-07-03 02:37:21 +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',
|
||||
dependencies: [
|
||||
'run-at.fn',
|
||||
'safe-self.fn',
|
||||
],
|
||||
});
|
||||
function setAttr(
|
||||
|
@ -3777,9 +3778,11 @@ function setAttr(
|
|||
attr = '',
|
||||
value = ''
|
||||
) {
|
||||
if ( typeof selector !== 'string' ) { return; }
|
||||
if ( selector === '' ) { return; }
|
||||
if ( attr === '' ) { return; }
|
||||
|
||||
const safe = safeSelf();
|
||||
const logPrefix = safe.makeLogPrefix('set-attr', attr, value);
|
||||
const validValues = [ '', 'false', 'true' ];
|
||||
let copyFrom = '';
|
||||
|
||||
|
@ -3797,7 +3800,6 @@ function setAttr(
|
|||
|
||||
const extractValue = elem => {
|
||||
if ( copyFrom !== '' ) {
|
||||
if ( copyFrom.startsWith('on') && copyFrom in elem ) { return; }
|
||||
return elem.getAttribute(copyFrom) || '';
|
||||
}
|
||||
return value;
|
||||
|
@ -3814,9 +3816,10 @@ function setAttr(
|
|||
for ( const elem of elems ) {
|
||||
const before = elem.getAttribute(attr);
|
||||
const after = extractValue(elem);
|
||||
if ( after === undefined ) { continue; }
|
||||
if ( after === before ) { continue; }
|
||||
if ( attr.startsWith('on') && attr in elem && after !== '' ) { continue; }
|
||||
elem.setAttribute(attr, after);
|
||||
safe.uboLog(logPrefix, `${attr}="${after}"`);
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue
Block a user