Created
November 27, 2012 02:13
-
-
Save nelix/4151970 to your computer and use it in GitHub Desktop.
Why not just make the API magically more like the way I want to write things.
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 workers = []; | |
| PageMod({ | |
| include: "*", | |
| contentScriptWhen: 'end', | |
| contentScriptFile: data.url("content.js"), | |
| attachTo: ["top", "existing"], | |
| onAttach: function(worker) { | |
| workers.push(worker); | |
| worker.on('detach', function () { | |
| log('worker detach'); | |
| detachWorker(this, workers); | |
| }); | |
| } | |
| )}; | |
| function detachWorker(worker, workerArray) { | |
| var index = workerArray.indexOf(worker); | |
| if(index != -1) { | |
| workerArray.splice(index, 1); | |
| } | |
| } | |
| function getWorker(tab, workerArray) { | |
| var _; | |
| function isTab(worker) { | |
| if (worker.tab === tab) _ = worker; | |
| } | |
| workerArray.forEach(isTab); | |
| return _; | |
| } | |
| function emitMessage(worker, eventName, eventData){ | |
| var message = { | |
| id: Math.random(), | |
| name: eventName, | |
| detail: eventData | |
| }; | |
| worker.postMessage(message); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment