Created
March 13, 2014 04:03
-
-
Save Noitidart/9521720 to your computer and use it in GitHub Desktop.
_ff-addon-snippet-FindAddonMgr - Finds the addon manager and returns an object holding its windows.
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
function findAddonMgr() { | |
//future: i plan to allow argument to this function so it searches just the CURRENT firefox window for addon manager, but for right now its global | |
//searches for addon manager tab in ALL FIREFOX WINDOWS and when found it returns the an object holding browser window (domWindow) and contentWindow (the window is the equivlent of gBrowser.contentWindow from scratchpad) | |
var windows = wm.getEnumerator('navigator:browser'); //gets all windows with gBrowser | |
while (windows.hasMoreElements()) { | |
var domWindow = windows.getNext(); | |
if (domWindow.gBrowser) { | |
if (domWindow.gBrowser.tabContainer) { | |
var browsers = domWindow.gBrowser.tabContainer.tabbrowser.browsers; //each tab is a browser | |
for (var i=0; i<browsers.length; i++) { | |
var loc = browsers[i].contentWindow.location; | |
//console.log('in this window tab ' + i + ' is at location of "' + loc + '"'); | |
if (loc == 'about:addons') { | |
return { | |
domWindow: domWindow, | |
gBrowser: domWindow.gBrowser, | |
contentWindow: browsers[i].contentWindow | |
}; | |
} | |
} | |
} else { | |
//no tab container | |
var loc = domWindow.gBrowser.contentWindow.location; | |
//console.log('no tab container in this window so just one gBrowser element. the location of this is "' + loc + '"'); | |
if (loc == 'about:addons') { | |
return { | |
domWindow: domWindow, | |
gBrowser: domWindow.gBrowser, | |
contentWindow: domWindow.gBrowser.contentWindow | |
}; | |
} | |
} | |
} else { | |
//window does not have gBrowser | |
//its unlikely, like 99.9% that about:addons is opened in a non-gBrowser'ed window so I dont care for this | |
} | |
} | |
return null; | |
} | |
var isManagerOpen = findAddonMgr(); | |
if (!isManagerOpen) { | |
//manager is not found so open it in the most recent browser window | |
Services.wm.getMostRecentWindow('navigator:browser').BrowserOpenAddonsMgr(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment