Skip to content

Instantly share code, notes, and snippets.

@notjosh
Created November 7, 2008 07:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save notjosh/22797 to your computer and use it in GitHub Desktop.
Save notjosh/22797 to your computer and use it in GitHub Desktop.
CmdUtils.CreateCommand({
name: 'tabs',
description: 'Count the number of tabs and windows you have open',
icon: 'https://addons.mozilla.org/img/app-icons/firefox.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;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment