Ubiquity tab count

I've been looking for ages for an easy way to show the number of tabs I have open without needing an extension.

(The problem is that Greasemonkey and such don't get access to the browser chrome, whereas extensions do)

Well, I compromised by installing Ubiquity.

Now an alt-space, 'tabs', will show "n tabs in m windows".

Here's the script:

CmdUtils.CreateCommand({
name: 'tabs',
description: 'Count the number of tabs and windows you have open',
icon: 'http://www.spreadfirefox.com/files/spreadfirefox_RCS_favicon.png',
author: { name: 'Joshua May', email: 'notjosh@gmail.com'},
homepage: 'http://notjosh.com/',
execute: function()
{
var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService(Components.interfaces.nsIWindowMediator);
var counts = this._count(wm);

var messageTemplate = '${tabs} tab${tabPlural} open in ${windows} window${windowPlural}';

displayMessage(CmdUtils.renderTemplate(messageTemplate, {
'tabs': counts.tab,
'windows': counts.window,
'tabPlural': 1 != counts.tab ? 's' : '',
'windowPlural': 1 != counts.window ? 's' : '',
}));
},
_count: function(wm)
{
var windowIterator = wm.getEnumerator('navigator:browser');

var window;
var counts = {
window: 0,
tab: 0
};

while (windowIterator.hasMoreElements())
{
window = windowIterator.getNext();
counts.window++;
counts.tab += window.document.getElementById('content').mTabs.length;
}

return counts;
}
});


Friday, November 7. 2008

0 Comments