Skip to content

Commit

Permalink
Added value input (selector)
Browse files Browse the repository at this point in the history
A selector to input a value (search term)
  • Loading branch information
jwillmer committed Feb 19, 2018
1 parent 2932f99 commit 2cd9a5b
Show file tree
Hide file tree
Showing 9 changed files with 349 additions and 277 deletions.
73 changes: 37 additions & 36 deletions extension/devtools/devtools_scraper_panel.html
Original file line number Diff line number Diff line change
@@ -1,45 +1,46 @@
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="../assets/bootstrap-3.0.0/css/bootstrap.css">
<link rel="stylesheet" href="../assets/jquery.bootstrapvalidator/bootstrapValidator.css">
<link rel="stylesheet" href="devtools_scraper_panel.css">
<script src="../assets/jquery-2.0.3.js"></script>
<script src="../assets/papaparse.min.js"></script>
<script src="../assets/pouchdb-nightly.min.js"></script>
<script src="../assets/bootstrap-3.0.0/js/bootstrap.js"></script>
<script src="../assets/d3.v3.js" charset="UTF-8"></script>
<script src="../assets/ICanHaz.js"></script>
<script src="../assets/jquery.bootstrapvalidator/bootstrapValidator.js"></script>
<script src="../scripts/BackgroundScript.js"></script>
<script src="../scripts/ContentScript.js"></script>
<script src="../scripts/Config.js"></script>
<script src="../scripts/Selector.js"></script>
<script src="../scripts/SelectorList.js"></script>
<script src="../scripts/Selector/SelectorElement.js"></script>
<script src="../scripts/Selector/SelectorLink.js"></script>
<script src="../scripts/Selector/SelectorPopupLink.js"></script>
<script src="../scripts/Selector/SelectorGroup.js"></script>
<script src="../scripts/Selector/SelectorText.js"></script>
<script src="../scripts/Selector/SelectorImage.js"></script>
<script src="../scripts/Selector/SelectorHTML.js"></script>
<link rel="stylesheet" href="../assets/bootstrap-3.0.0/css/bootstrap.css">
<link rel="stylesheet" href="../assets/jquery.bootstrapvalidator/bootstrapValidator.css">
<link rel="stylesheet" href="devtools_scraper_panel.css">
<script src="../assets/jquery-2.0.3.js"></script>
<script src="../assets/papaparse.min.js"></script>
<script src="../assets/pouchdb-nightly.min.js"></script>
<script src="../assets/bootstrap-3.0.0/js/bootstrap.js"></script>
<script src="../assets/d3.v3.js" charset="UTF-8"></script>
<script src="../assets/ICanHaz.js"></script>
<script src="../assets/jquery.bootstrapvalidator/bootstrapValidator.js"></script>
<script src="../scripts/BackgroundScript.js"></script>
<script src="../scripts/ContentScript.js"></script>
<script src="../scripts/Config.js"></script>
<script src="../scripts/Selector.js"></script>
<script src="../scripts/SelectorList.js"></script>
<script src="../scripts/Selector/SelectorElement.js"></script>
<script src="../scripts/Selector/SelectorLink.js"></script>
<script src="../scripts/Selector/SelectorPopupLink.js"></script>
<script src="../scripts/Selector/SelectorGroup.js"></script>
<script src="../scripts/Selector/SelectorText.js"></script>
<script src="../scripts/Selector/SelectorValue.js"></script>
<script src="../scripts/Selector/SelectorImage.js"></script>
<script src="../scripts/Selector/SelectorHTML.js"></script>
<script src="../scripts/Selector/SelectorElementAttribute.js"></script>
<script src="../scripts/Selector/SelectorElementStyle.js"></script>
<script src="../scripts/Selector/SelectorTable.js"></script>
<script src="../scripts/Selector/SelectorElementScroll.js"></script>
<script src="../scripts/Selector/SelectorElementClick.js"></script>
<script src="../scripts/Sitemap.js"></script>
<script src="../scripts/SelectorGraph.js"></script>
<script src="../scripts/SelectorGraphv2.js"></script>
<script src="../scripts/Store.js"></script>
<script src="../scripts/StoreDevtools.js"></script>
<script src="../scripts/Controller.js"></script>
<script src="../scripts/Selector/SelectorTable.js"></script>
<script src="../scripts/Selector/SelectorElementScroll.js"></script>
<script src="../scripts/Selector/SelectorElementClick.js"></script>
<script src="../scripts/Sitemap.js"></script>
<script src="../scripts/SelectorGraph.js"></script>
<script src="../scripts/SelectorGraphv2.js"></script>
<script src="../scripts/Store.js"></script>
<script src="../scripts/StoreDevtools.js"></script>
<script src="../scripts/Controller.js"></script>

<script src="../scripts/App.js"></script>
<script src="../scripts/DateUtils/SimpleDateFormatter.js"></script>
<script src="../scripts/DateUtils/DateRoller.js"></script>
<script src="../scripts/DateUtils/DatePatternSupport.js"></script>
<script src="../scripts/App.js"></script>

<script src="../scripts/DateUtils/SimpleDateFormatter.js"></script>
<script src="../scripts/DateUtils/DateRoller.js"></script>
<script src="../scripts/DateUtils/DatePatternSupport.js"></script>
</head>
<body></body>
</html>
103 changes: 56 additions & 47 deletions extension/devtools/views/SelectorEdit.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<span class="input-group-btn">
<button class="btn btn-default" action="select-selector" type="button">Select</button>
<button class="btn btn-default" action="preview-selector" type="button" data-toggle="button">Element preview</button>
<button class="btn btn-default" action="preview-selector-data" type="button">Data preview</button>
<button class="btn btn-default" action="preview-selector-data" type="button">Data preview</button>
</span>
<input type="text" class="form-control selector-value" id="selector" name="selector" value="{{selector.selector}}">
</div>
Expand Down Expand Up @@ -71,7 +71,7 @@
<div class="input-group">
<span class="input-group-btn">
<button class="btn btn-default" action="select-table-data-row-selector" type="button">Select</button>
<button class="btn btn-default" action="preview-table-row-selector" type="button" data-toggle="button">Element preview</button>
<button class="btn btn-default" action="preview-table-row-selector" type="button" data-toggle="button">Element preview</button>
</span>
<input type="text" class="form-control selector-value" id="tableDataRowSelector" name="tableDataRowSelector" value="{{selector.tableDataRowSelector}}">
</div>
Expand Down Expand Up @@ -130,7 +130,7 @@
<div class="col-sm-8">
<div class="checkbox">
<label>
<input type="checkbox" name="multiple" {{#selector.multiple}}checked="checked"{{/selector.multiple}}>
<input type="checkbox" name="multiple" {{#selector.multiple}} checked="checked" {{/selector.multiple}}>
</label>
</div>
</div>
Expand All @@ -142,7 +142,7 @@
<div class="col-sm-8">
<div class="checkbox">
<label>
<input type="checkbox" name="discardInitialElements" {{#selector.discardInitialElements}}checked="checked"{{/selector.discardInitialElements}}>
<input type="checkbox" name="discardInitialElements" {{#selector.discardInitialElements}} checked="checked" {{/selector.discardInitialElements}}>
Discard initial elements that are available before click
</label>
</div>
Expand All @@ -155,7 +155,7 @@
<div class="col-sm-8">
<div class="checkbox">
<label>
<input type="checkbox" name="downloadImage" {{#selector.downloadImage}}checked="checked"{{/selector.downloadImage}}>
<input type="checkbox" name="downloadImage" {{#selector.downloadImage}} checked="checked" {{/selector.downloadImage}}>
</label>
</div>
</div>
Expand All @@ -170,6 +170,15 @@
</div>
</div>

<!-- insertValue -->
<div class="form-group feature feature-insertValue">
<label for="insertValue" class="col-sm-2 control-label">Text value</label>

<div class="col-sm-8">
<input type="text" class="form-control" name="insertValue" id="insertValue" placeholder="Text value to insert" value="{{selector.insertValue}}">
</div>
</div>

<!-- extractStyle -->
<div class="form-group feature feature-extractStyle">
<label for="extractStyle" class="col-sm-2 control-label">Style name</label>
Expand All @@ -188,10 +197,10 @@
<span class="help-block" style="margin-top: -5px;">Trim will be applied before regex.</span>
</div>
<div class="checkbox">
<label><input type="checkbox" name="removeHtml" {{#selector.textmanipulation.removeHtml}}checked="checked"{{/selector.textmanipulation.removeHtml}}> Remove HTML</label>
<label><input type="checkbox" name="removeHtml" {{#selector.textmanipulation.removeHtml}} checked="checked" {{/selector.textmanipulation.removeHtml}}> Remove HTML</label>
</div>
<div class="checkbox">
<label><input type="checkbox" name="trimText" {{#selector.textmanipulation.trimText}}checked="checked"{{/selector.textmanipulation.trimText}}> Trim Text</label>
<label><input type="checkbox" name="trimText" {{#selector.textmanipulation.trimText}} checked="checked" {{/selector.textmanipulation.trimText}}> Trim Text</label>
</div>
<div class="form-inline" style="padding-top: 7px">
<label>Replace text:<input type="text" class="form-control col-sm-6" name="replaceText" id="replaceText" placeholder="Replace text" value="{{selector.textmanipulation.replaceText}}"></label>
Expand All @@ -202,7 +211,7 @@
<label>Text Suffix:<input type="text" class="form-control col-sm-6" name="textSuffix" id="textSuffix" placeholder="Suffix" value="{{selector.textmanipulation.textSuffix}}"></label>
</div>
</div>
</div>
</div>

<div class="form-group feature feature-delay">
<label for="delay" class="col-sm-2 control-label">Delay (ms)</label>
Expand All @@ -223,52 +232,52 @@
</div>
</div>

<div class="form-group">
<label for="parentSelectors" class="col-sm-2 control-label">Parent Selectors</label>
<div class="form-group">
<label for="parentSelectors" class="col-sm-2 control-label">Parent Selectors</label>

<div class="input-group col-sm-8">
<select multiple class="form-control" id="parentSelectors" name="parentSelectors">
{{#selectorIds}}
<option value="{{.}}">{{.}}</option>
{{/selectorIds}}
</select>
</div>
<div class="input-group col-sm-8">
<select multiple class="form-control" id="parentSelectors" name="parentSelectors">
{{#selectorIds}}
<option value="{{.}}">{{.}}</option>
{{/selectorIds}}
</select>
</div>
</div>

<div class="form-group feature feature-columns">
<label class="col-sm-2 control-label">Table columns</label>

<div class="col-sm-8">
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th>Column</th>
<th>Result key</th>
<th>Include into result</th>
</tr>
</thead>
<tbody>
{{#selector.columns}}
<tr>
<td><input class="column-header" type="hidden" name="column[header][]" value="{{header}}">{{header}}</td>
<td><input class="column-name form-control" type="text" name="column[name][]" value="{{name}}"></td>
<td><input class="column-extract" type="checkbox" name="column[extract][]" {{#extract}}checked="checked"{{/extract}}></td>
</tr>
{{/selector.columns}}
</tbody>
</table>
</div>
<div class="form-group feature feature-columns">
<label class="col-sm-2 control-label">Table columns</label>

<div class="col-sm-8">
<table class="table table-bordered table-condensed">
<thead>
<tr>
<th>Column</th>
<th>Result key</th>
<th>Include into result</th>
</tr>
</thead>
<tbody>
{{#selector.columns}}
<tr>
<td><input class="column-header" type="hidden" name="column[header][]" value="{{header}}">{{header}}</td>
<td><input class="column-name form-control" type="text" name="column[name][]" value="{{name}}"></td>
<td><input class="column-extract" type="checkbox" name="column[extract][]" {{#extract}} checked="checked" {{/extract}}></td>
</tr>
{{/selector.columns}}
</tbody>
</table>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<button class="btn btn-primary" action="save-selector">Save selector</button> <button action="cancel-selector-editing" class="btn btn-default">Cancel</button>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<button class="btn btn-primary" action="save-selector">Save selector</button> <button action="cancel-selector-editing" class="btn btn-default">Cancel</button>
</div>
</div>

<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">

</div>
</div>
</div>
</form>
2 changes: 2 additions & 0 deletions extension/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"scripts/Selector/SelectorLink.js",
"scripts/Selector/SelectorPopupLink.js",
"scripts/Selector/SelectorText.js",
"scripts/Selector/SelectorValue.js",
"scripts/Selector/SelectorImage.js",
"scripts/Selector/SelectorHTML.js",
"scripts/Selector/SelectorElementAttribute.js",
Expand Down Expand Up @@ -85,6 +86,7 @@
"scripts/Selector/SelectorLink.js",
"scripts/Selector/SelectorPopupLink.js",
"scripts/Selector/SelectorText.js",
"scripts/Selector/SelectorValue.js",
"scripts/Selector/SelectorImage.js",
"scripts/Selector/SelectorHTML.js",
"scripts/Selector/SelectorElementAttribute.js",
Expand Down
16 changes: 11 additions & 5 deletions extension/scripts/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -737,10 +737,14 @@ SitemapController.prototype = {
selector: selector,
selectorIds: selectorIds,
selectorTypes: [
{
type: 'SelectorText',
title: 'Text'
},
{
type: 'SelectorText',
title: 'Text'
},
{
type: 'SelectorValue',
title: 'Value Input'
},
{
type: 'SelectorLink',
title: 'Link'
Expand Down Expand Up @@ -876,7 +880,8 @@ SitemapController.prototype = {
var clickPopup = $("#edit-selector [name=clickPopup]").is(":checked");
var delay = $("#edit-selector [name=delay]").val();
var extractAttribute = $("#edit-selector [name=extractAttribute]").val();
var extractStyle = $("#edit-selector [name=extractStyle]").val();
var extractStyle = $("#edit-selector [name=extractStyle]").val();
var insertValue = $("#edit-selector [name=insertValue]").val();
var parentSelectors = $("#edit-selector [name=parentSelectors]").val();
var columns = [];
var $columnHeaders = $("#edit-selector .column-header");
Expand Down Expand Up @@ -925,6 +930,7 @@ SitemapController.prototype = {
clickPopup: clickPopup,
extractAttribute: extractAttribute,
extractStyle: extractStyle,
insertValue: insertValue,
parentSelectors: parentSelectors,
columns:columns,
delay:delay,
Expand Down
2 changes: 1 addition & 1 deletion extension/scripts/Scraper.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ Scraper.prototype = {
},

// @TODO remove recursion and add an iterative way to run these jobs.
_run: function () {
_run: function () {

var job = this.queue.getNextJob();
if (job === false) {
Expand Down
51 changes: 51 additions & 0 deletions extension/scripts/Selector/SelectorValue.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
var SelectorValue = {

canReturnMultipleRecords: function () {
return false;
},

canHaveChildSelectors: function () {
return true;
},

canHaveLocalChildSelectors: function () {
return true;
},

canCreateNewJobs: function () {
return false;
},

willReturnElements: function () {
return false;
},

_getData: function (parentElement) {

var dfd = $.Deferred();

var elements = this.getDataElements(parentElement);

var result = [];
$(elements).each(function (k, element) {
$(element).val(this.insertValue);
}.bind(this));


var data = {};
data[this.id] = this.insertValue;
result.push(data);


dfd.resolve(result);
return dfd.promise();
},

getDataColumns: function () {
return [];
},

getFeatures: function () {
return ['insertValue']
}
};
Loading

1 comment on commit 2cd9a5b

@jwillmer
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Referencing #16

Please sign in to comment.