Skip to content

Instantly share code, notes, and snippets.

@Gozala
Created December 30, 2010 11:14
Show Gist options
  • Select an option

  • Save Gozala/759683 to your computer and use it in GitHub Desktop.

Select an option

Save Gozala/759683 to your computer and use it in GitHub Desktop.
Hack that executes task in a page-mod of an active tab.
var tabs = require('tabs');
var mods = require('page-mod');
myWidget.on('click', function() {
mods.PageMod({
include: tabs.activeTab.url,
contentScriptWhen: 'ready',
contentScript: 'new ' + function Worker() {
window.addEventListener('message', function listener(e) {
if ('go mod' == e.data) {
// Remove this listener to make sure that task is executed only once.
window.removeEventListener('message', listener, false);
// Logic of your task goes here ....
}
}, false);
},
onAttach: function onAttach(worker) {
// Telling active tab's page-mod to execute a task.
tabs.activeTab.url = 'javascript:window.postMessage("go mod", "*")'
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment