From 316bc5fbaffdda84f73cf85e318fa8b6744f99de Mon Sep 17 00:00:00 2001 From: Saleh Ahmed Panna Date: Wed, 7 Dec 2016 17:41:54 +0600 Subject: [PATCH] Added Limit for clicking --- docs/Selectors/Element click selector.md | 1 + extension/devtools/views/SelectorEdit.html | 11 ++++++++++- extension/scripts/Controller.js | 15 ++++++++++++--- .../scripts/Selector/SelectorElementClick.js | 8 +++++--- 4 files changed, 28 insertions(+), 7 deletions(-) diff --git a/docs/Selectors/Element click selector.md b/docs/Selectors/Element click selector.md index c46be9fd..48ee4ead 100644 --- a/docs/Selectors/Element click selector.md +++ b/docs/Selectors/Element click selector.md @@ -18,6 +18,7 @@ events triggered by the button. be clicked to load more elements. * click type - type of how the selector knows when there will be no new elements and clicking should stop. + * click limit - the number of clicks you want the selector to perform. * click element uniqueness - type of how selector knows which buttons are already clicked. * multiple - multiple records are being extracted (almost always should be diff --git a/extension/devtools/views/SelectorEdit.html b/extension/devtools/views/SelectorEdit.html index 04928fc9..b7fa6274 100644 --- a/extension/devtools/views/SelectorEdit.html +++ b/extension/devtools/views/SelectorEdit.html @@ -89,6 +89,15 @@ + +
+ + +
+ +
+
+
@@ -110,7 +119,7 @@
- +
diff --git a/extension/scripts/Controller.js b/extension/scripts/Controller.js index 3caa4cab..79b1f8c6 100644 --- a/extension/scripts/Controller.js +++ b/extension/scripts/Controller.js @@ -693,6 +693,13 @@ SitemapController.prototype = { } } }, + clickLimit: { + validators: { + numeric: { + message: 'Click limit must be numeric' + } + } + }, parentSelectors: { validators: { notEmpty: { @@ -830,7 +837,7 @@ SitemapController.prototype = { var sitemap = this.state.currentSitemap; var selector = this.state.currentSelector; var newSelector = this.getCurrentlyEditedSelector(); - + // cancel submit if invalid form if(!this.isValidForm()) { return false; @@ -863,6 +870,7 @@ SitemapController.prototype = { var clickPopup = $("#edit-selector [name=clickPopup]").is(":checked"); var regex = $("#edit-selector [name=regex]").val(); var delay = $("#edit-selector [name=delay]").val(); + var clickLimit = $("#edit-selector [name=clickLimit]").val(); var extractAttribute = $("#edit-selector [name=extractAttribute]").val(); var parentSelectors = $("#edit-selector [name=parentSelectors]").val(); var columns = []; @@ -898,7 +906,8 @@ SitemapController.prototype = { extractAttribute:extractAttribute, parentSelectors: parentSelectors, columns:columns, - delay:delay + delay:delay, + clickLimit:clickLimit }); return newSelector; }, @@ -1004,7 +1013,7 @@ SitemapController.prototype = { var requestInterval = $("input[name=requestInterval]").val(); var pageLoadDelay = $("input[name=pageLoadDelay]").val(); - + var sitemap = this.state.currentSitemap; var request = { scrapeSitemap: true, diff --git a/extension/scripts/Selector/SelectorElementClick.js b/extension/scripts/Selector/SelectorElementClick.js index 87592803..8e9fefb4 100644 --- a/extension/scripts/Selector/SelectorElementClick.js +++ b/extension/scripts/Selector/SelectorElementClick.js @@ -82,6 +82,7 @@ var SelectorElementClick = { _getData: function(parentElement) { var delay = parseInt(this.delay) || 0; + var clickLimit = parseInt(this.clickLimit) || 1; var deferredResponse = $.Deferred(); var foundElements = new UniqueElementList('uniqueHTMLText'); var clickElements = this.getClickElements(parentElement); @@ -109,7 +110,7 @@ var SelectorElementClick = { // infinitely scroll down and find all items var interval = setInterval(function() { - + // find those click elements that are not in the black list var allClickElements = this.getClickElements(parentElement); clickElements = []; @@ -145,7 +146,7 @@ var SelectorElementClick = { // continue clicking and add delay, but if there is nothing // more to click the finish //console.log("total buttons", clickElements.length) - if(clickElements.length === 0) { + if(clickElements.length === 0 || clickLimit < 1) { clearInterval(interval); deferredResponse.resolve(foundElements); } @@ -158,6 +159,7 @@ var SelectorElementClick = { } this.triggerButtonClick(currentClickElement); nextElementSelection = now+delay; + clickLimit--; } }.bind(this), 50); @@ -169,6 +171,6 @@ var SelectorElementClick = { }, getFeatures: function () { - return ['multiple', 'delay', 'clickElementSelector', 'clickType', 'discardInitialElements', 'clickElementUniquenessType'] + return ['multiple', 'delay', 'clickElementSelector', 'clickType', 'discardInitialElements', 'clickElementUniquenessType', 'clickLimit'] } };