Skip to content

Commit

Permalink
switched from a pag-mod implementation to a tabs implementation - sav…
Browse files Browse the repository at this point in the history
…es on memory for pages with many iframes, etc.
  • Loading branch information
canuckistani committed Jan 28, 2012
1 parent 7d003c0 commit cb4233d
Showing 1 changed file with 17 additions and 8 deletions.
25 changes: 17 additions & 8 deletions lib/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@ var pageMod = require('page-mod'),
url = require('url'),
{Cc, Ci} = require('chrome');

pageMod.PageMod({
include: "*",
contentScriptWhen: 'ready',
contentScriptFile: [
data.url('jquery-1.7.1.min.js'),
data.url('dotjs.js')
],
onAttach: function onAttach(worker) {

/*
*
*/
var tabs = require("tabs");

tabs.on('ready', function(tab) {
// test for the worker as a property of the tab object.
if (typeof(tab._dotjs_worker) === 'undefined') {
let worker = tab.attach({
contentScriptFile: [data.url('jquery-1.7.1.min.js'), data.url('dotjs.js')]
});

worker.on('message', function(msg) {
var domain = url.URL(msg).host,
dirSvc = Cc['@mozilla.org/file/directory_service;1']
Expand All @@ -23,6 +28,7 @@ pageMod.PageMod({
if (domain.indexOf('www.') === 0) {
domain = domain.substring(4, domain.length);
}

files = ['default', domain];
for (var i=0; i < files.length; i++) {
filename = file.join(homeDir, jsDir, files[i]);
Expand All @@ -45,5 +51,8 @@ pageMod.PageMod({
}
}
});
// later, add the worker as a property od the tab object, so we don't inject
// the tab more than once.
tab._dotjs_worker = worker;
}
});

0 comments on commit cb4233d

Please sign in to comment.