-
-
Save notjosh/22799 to your computer and use it in GitHub Desktop.
This file contains 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
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; | |
} | |
}); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment