From f122ce7320aa12f9ceaa9603fe3a4d3848a7f3e8 Mon Sep 17 00:00:00 2001 From: Raymond Hill Date: Mon, 16 Oct 2023 19:53:48 -0400 Subject: [PATCH] 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. --- assets/resources/scriptlets.js | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/assets/resources/scriptlets.js b/assets/resources/scriptlets.js index 35d5ac988..a6d6194ea 100644 --- a/assets/resources/scriptlets.js +++ b/assets/resources/scriptlets.js @@ -3896,6 +3896,7 @@ builtinScriptlets.push({ world: 'ISOLATED', dependencies: [ 'run-at-html-element.fn', + 'safe-self.fn', ], }); function trustedClickElement( @@ -3905,6 +3906,12 @@ function trustedClickElement( ) { 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*/) .filter(s => { try { @@ -3928,15 +3935,22 @@ function trustedClickElement( }; const next = notFound => { - if ( selectorList.length === 0 ) { return terminate(); } + if ( selectorList.length === 0 ) { + uboLog(`trusted-click-element: Completed`); + return terminate(); + } const tnow = Date.now(); - if ( tnow >= tbye ) { return terminate(); } + if ( tnow >= tbye ) { + uboLog(`trusted-click-element: Timed out`); + return terminate(); + } if ( notFound ) { observe(); } const delay = Math.max(notFound ? tbye - tnow : tnext - tnow, 1); next.timer = setTimeout(( ) => { next.timer = undefined; process(); }, delay); + uboLog(`trusted-click-element: Waiting for ${selectorList[0]}...`); }; next.stop = ( ) => { if ( next.timer === undefined ) { return; } @@ -3980,6 +3994,7 @@ function trustedClickElement( selectorList.unshift(selector); return next(true); } + uboLog(`trusted-click-element: Clicked ${selector}`); elem.click(); tnext += clickDelay; next();