AdguardTeam / Scriptlets

AdGuard scriptlets library
GNU General Public License v3.0
148 stars 29 forks source link

Fix 'prevent-setTimeout' — scriptlets does not execute immediately on intaa.net #314

Closed zloyden closed 1 year ago

zloyden commented 1 year ago

The configuration and other info you can find here https://github.com/AdguardTeam/AdguardFilters/issues/150950. For some reason, this scriptlet intaa.net#%#//scriptlet('prevent-setTimeout', 'getElementsByTagName')cannot be executed on the first visit to the page, but after the next refresh it works fine.

stanislav-atr commented 1 year ago

@zloyden, intaa.net#%#//scriptlet('prevent-setTimeout', 'gptScriptLoaded') would be the scriptlet to match the callback, but ctlbny(),which applies animation, is not always being called through setTimeout callback:

document.addEventListener('DOMContentLoaded', () => {
    const e = Date.now();
    const t = function () {
        if (gptScriptLoaded) {
            const n = setInterval(() => {
                if (calcHeight() !== 0) {
                    clearInterval(n);
                    clearTimeout(a);
                    codeShift();
                }
            }, 300);

            let a = setTimeout(() => {
                clearInterval(n);
                ctlbny();
            }, 7e3);
        } else {
            // eslint-disable-next-line no-unused-expressions
            Date.now() - e < 7e3 ? setTimeout(t, 100) : ctlbny();
        }
    };

    t();
});

#%#//scriptlet('prevent-addEventListener', 'DOMContentLoaded', 'gptScriptLoaded') would work here.

zloyden commented 1 year ago

Seems that the scriptlet works fine on my end. Thanks for the explanation. Since then, another solution was added, so you can close this task.