mirror of
https://github.com/gorhill/uBlock.git
synced 2024-10-06 09:37:12 +02:00
Add logging ability to trusted-click-element
If the vararg `, log, 1` is present, the scriptlet will log to the console it's execution steps. Works only in dev build.
This commit is contained in:
parent
5a24fad8ad
commit
f122ce7320
@ -3896,6 +3896,7 @@ builtinScriptlets.push({
|
|||||||
world: 'ISOLATED',
|
world: 'ISOLATED',
|
||||||
dependencies: [
|
dependencies: [
|
||||||
'run-at-html-element.fn',
|
'run-at-html-element.fn',
|
||||||
|
'safe-self.fn',
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
function trustedClickElement(
|
function trustedClickElement(
|
||||||
@ -3905,6 +3906,12 @@ function trustedClickElement(
|
|||||||
) {
|
) {
|
||||||
if ( extraMatch !== '' ) { return; }
|
if ( extraMatch !== '' ) { return; }
|
||||||
|
|
||||||
|
const safe = safeSelf();
|
||||||
|
const extraArgs = safe.getExtraArgs(Array.from(arguments), 3);
|
||||||
|
const uboLog = extraArgs.log !== undefined
|
||||||
|
? ((...args) => { safe.uboLog(...args); })
|
||||||
|
: (( ) => { });
|
||||||
|
|
||||||
const selectorList = selectors.split(/\s*,\s*/)
|
const selectorList = selectors.split(/\s*,\s*/)
|
||||||
.filter(s => {
|
.filter(s => {
|
||||||
try {
|
try {
|
||||||
@ -3928,15 +3935,22 @@ function trustedClickElement(
|
|||||||
};
|
};
|
||||||
|
|
||||||
const next = notFound => {
|
const next = notFound => {
|
||||||
if ( selectorList.length === 0 ) { return terminate(); }
|
if ( selectorList.length === 0 ) {
|
||||||
|
uboLog(`trusted-click-element: Completed`);
|
||||||
|
return terminate();
|
||||||
|
}
|
||||||
const tnow = Date.now();
|
const tnow = Date.now();
|
||||||
if ( tnow >= tbye ) { return terminate(); }
|
if ( tnow >= tbye ) {
|
||||||
|
uboLog(`trusted-click-element: Timed out`);
|
||||||
|
return terminate();
|
||||||
|
}
|
||||||
if ( notFound ) { observe(); }
|
if ( notFound ) { observe(); }
|
||||||
const delay = Math.max(notFound ? tbye - tnow : tnext - tnow, 1);
|
const delay = Math.max(notFound ? tbye - tnow : tnext - tnow, 1);
|
||||||
next.timer = setTimeout(( ) => {
|
next.timer = setTimeout(( ) => {
|
||||||
next.timer = undefined;
|
next.timer = undefined;
|
||||||
process();
|
process();
|
||||||
}, delay);
|
}, delay);
|
||||||
|
uboLog(`trusted-click-element: Waiting for ${selectorList[0]}...`);
|
||||||
};
|
};
|
||||||
next.stop = ( ) => {
|
next.stop = ( ) => {
|
||||||
if ( next.timer === undefined ) { return; }
|
if ( next.timer === undefined ) { return; }
|
||||||
@ -3980,6 +3994,7 @@ function trustedClickElement(
|
|||||||
selectorList.unshift(selector);
|
selectorList.unshift(selector);
|
||||||
return next(true);
|
return next(true);
|
||||||
}
|
}
|
||||||
|
uboLog(`trusted-click-element: Clicked ${selector}`);
|
||||||
elem.click();
|
elem.click();
|
||||||
tnext += clickDelay;
|
tnext += clickDelay;
|
||||||
next();
|
next();
|
||||||
|
Loading…
Reference in New Issue
Block a user