var deleteSpam = { count: 0, list: null, timeout: 500, //Selector of cross(x) link crossSelector: '.userContentWrapper [aria-label="Delete"]', //Selector for buttons wrapper in overlay box which appears when we click on cross icon overlayPresenseSelector: '.uiOverlayFooter', //Delete button selector on overlay box confirmDeleteButtonSelector: 'button.layerConfirm', init: function() { this.list = document.querySelectorAll(this.crossSelector); this.overlay(); }, checkOverlay: function() { var that = this; var overlay = document.querySelector(this.overlayPresenseSelector); if (!overlay) { this.overlay(); } else { setTimeout(function() { that.checkOverlay(); }, this.timeout); } }, overlay: function() { var that = this; var event = document.createEvent('HTMLEvents'); event.initEvent('click', true, false); if (this.list.length <= this.count) { return false; } this.list[this.count].dispatchEvent(event); setTimeout(function() { that.confirm(); }, this.timeout); }, confirm: function() { var that = this; var button = document.querySelector(this.confirmDeleteButtonSelector); var event = document.createEvent('HTMLEvents'); event.initEvent('click', true, false); if (button) { button.dispatchEvent(event); this.count++; setTimeout(function() { that.checkOverlay(); }, this.timeout); } else { setTimeout(function() { that.confirm(); }, this.timeout); } } }.init();