Created
December 30, 2010 11:14
-
-
Save Gozala/759683 to your computer and use it in GitHub Desktop.
Hack that executes task in a page-mod of an active tab.
This file contains hidden or 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
| 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