Created
June 23, 2014 18:32
-
-
Save jeffgca/6c299c812bbe582d9efb to your computer and use it in GitHub Desktop.
page-workr scraping example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let { Page } = require('sdk/page-worker'); | |
let self = require('sdk/self'); | |
let { ActionButton } = require("sdk/ui/button/action"); | |
let worker = Page({ | |
contentScriptFile: [self.data.url('worker.js'), | |
self.data.url('jquery.js')] | |
}); | |
worker.on('fetched', function(data) { | |
// do something with the data | |
}); | |
// a basic button to trigger the fetch command. | |
let button = ActionButton({ | |
id: "my-button", | |
label: "my button", | |
icon: { | |
"16": "./firefox-16.png", | |
"32": "./firefox-32.png" | |
}, | |
onClick: function(state) { | |
worker.port.emit('fetch'); | |
} | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
self.port.on('fetch', function() { | |
// use jQuery to extract some data | |
var something = $('.classname').html(); | |
// the data you send can only be arrays, text, numbers, not a whole jQuery result | |
self.port.emit('fetched', something); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment