uzairfarooq / arrive

Watch for DOM elements creation and removal
MIT License
869 stars 99 forks source link

why it rescan elements exponentially? #86

Open k-dmitrii opened 1 year ago

k-dmitrii commented 1 year ago

sorry, maybe it's newbie question, i'm not good at programming. i trying to write script for browser extension tampermonkey that filtering some elements and noticed that 'arrive' processed already existing elements this page aliespress coupon center show 20 elements, when you scroll down it show another 20 and etc. (20, 40, 60, 80...) but 'arrive' processed exponentially: 20_406080__100_120... <- elements on page 20_60_120_200_300_420... <- 'arrive' processed so it sum up diagonally '/' (0+20=20, 20+40=60, 60+60=120, 120+80=200...) tampermonkey simple script i used to check this

// ==UserScript==
// @name         New Userscript
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  try to take over the world!
// @author       You
// @match        https://campaign.aliexpress.com/wow/gcp/ae/channel/ae/accelerate/tupr*
// @require      https://cdnjs.cloudflare.com/ajax/libs/arrive/2.4.1/arrive.min.js
// @icon         data:image/gif;base64,R0lGODlhAQABAAAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==
// @grant        none
// @run-at       document-body
// ==/UserScript==

(function() {
    'use strict';

    let i=0;
    document.arrive('div[exp_type="coupon_exposure"]', function () {
        i++;
/*        if (isInteger(i/2)) {
            this.remove();
        }
*/
        if (isInteger(i/20)) {
            alert(document.querySelectorAll('div[exp_type="coupon_exposure"]').length + ' elements on page\n' + i + ' document.arrive processed');
        }
    });

function isInteger(num) {
  return (num ^ 0) === num;
}

})();

if remove some elements from page (commented 'this.remove'), like every 2nd, the sequence will remain 20_60_120_200_300_420... is it normal or not? when i use filtering action in script it will do its actions again and again on the same elements :/

matthew-dean commented 6 months ago

That's concerning 🤔