Skip to content

Commit

Permalink
Get first example
Browse files Browse the repository at this point in the history
  • Loading branch information
furstenheim-geoblink committed Jan 17, 2018
1 parent c015cc0 commit 8ae3d3b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
16 changes: 15 additions & 1 deletion extension/scripts/BackgroundScript.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var jquery = require('jquery-deferred')
const debug = require('debug')('web-scraper-headless:background-script')

/**
* ContentScript that can be called from anywhere within the extension
*/
Expand All @@ -20,8 +22,20 @@ var BackgroundScript = {
currentWindow: true
}, function (tabs) {
if (tabs.length < 1) {
debug('There seems to be no active tab in the current window. Let us try only active')
chrome.tabs.query({
active: true,
windowType: 'normal'
}, function (tabs) {
if (tabs.length < 1) {
debug('Could not find tab')
deferredResponse.reject("couldn't find the active tab")
} else {
const tabId = tabs[0].id
deferredResponse.resolve(tabId)
}
})
// @TODO must be running within popup. maybe find another active window?
deferredResponse.reject("couldn't find the active tab")
} else {
var tabId = tabs[0].id
deferredResponse.resolve(tabId)
Expand Down
3 changes: 3 additions & 0 deletions extension/scripts/ContentScript.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var ContentSelector = require('./ContentSelector')
var jquery = require('jquery-deferred')
const debug = require('debug')('web-scraper-headless:content-script')

/**
* ContentScript that can be called from anywhere within the extension
*/
Expand All @@ -15,6 +17,7 @@ var ContentScript = {
var deferredHTML = jquery.Deferred()
var html = $(request.CSSSelector).clone().wrap('<p>').parent().html()
deferredHTML.resolve(html)
debug('Send html', html)
return deferredHTML.promise()
},

Expand Down
10 changes: 5 additions & 5 deletions extension/scripts/Controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -1207,7 +1207,7 @@ var window = this.window
}.bind(this))
}

if (selector.type === 'SelectorGoogMapIDS') {
if (selector.type === 'SelectorGoogMapID') {
this.getSelectorHTML().done(function (html) {
var mapSelectorFromDiv = SelectorGoogMapID.getMapsSelectorFromDivHTML(html, {$, document, window})
$('input[name=mapsSelectorFromDiv]').val(mapSelectorFromDiv)
Expand Down Expand Up @@ -1298,8 +1298,8 @@ var window = this.window
*/
getSelectorHTML: function () {
var $ = this.$
var document = this.document
var window = this.window
var document = this.document
var window = this.window
var sitemap = this.getCurrentlyEditedSelectorSitemap()
var selector = this.getCurrentlyEditedSelector()
var currentStateParentSelectorIds = this.getCurrentStateParentSelectorIds()
Expand All @@ -1310,8 +1310,8 @@ var window = this.window
},
previewSelector: function (button) {
var $ = this.$
var document = this.document
var window = this.window
var document = this.document
var window = this.window
if (!$(button).hasClass('preview')) {
var sitemap = this.getCurrentlyEditedSelectorSitemap()
var selector = this.getCurrentlyEditedSelector()
Expand Down
2 changes: 1 addition & 1 deletion extension/scripts/Selector/SelectorGoogMapID.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ var SelectorGoogMapID = {

getItemCSSSelector: function () {
// We get the container
return 'div'
return '*'
},

getMapsSelectorFromDivHTML: function (html, options = {}) {
Expand Down

0 comments on commit 8ae3d3b

Please sign in to comment.