From 64dcac17e4857968ca7004ae06b6c7e1d8bbc606 Mon Sep 17 00:00:00 2001 From: ElbertF Date: Mon, 26 Dec 2011 16:40:21 +1100 Subject: [PATCH] Analyze response headers, listen for location and tab changes, added context menu --- adapters/firefox/content/js/adapter.js | 59 ++++++++++--------- adapters/firefox/content/xul/wappalyzer.xul | 10 +++- adapters/firefox/locale/en-US/wappalyzer.dtd | 8 ++- .../locale/en-US/wappalyzer.properties | 3 +- share/js/wappalyzer.js | 2 +- 5 files changed, 50 insertions(+), 32 deletions(-) diff --git a/adapters/firefox/content/js/adapter.js b/adapters/firefox/content/js/adapter.js index d5bf45ac2..efddd488f 100644 --- a/adapters/firefox/content/js/adapter.js +++ b/adapters/firefox/content/js/adapter.js @@ -7,7 +7,7 @@ var w = wappalyzer; - var $; + var $, strings; w.adapter = { /** @@ -28,24 +28,7 @@ w.log('w.adapter: browser window loaded'); - // Listen for tab events - gBrowser.addTabsProgressListener({ - /* - onLocationChange: function(progress, request, location, flags) { - w.log('tab location change: ' + location.URI.spec); - - w.adapter('displayApps', { url: location.URI.spec }); - } - */ - - /* - onStateChange: function(browser, progress, request, flags, status) { - if ( (flag & Components.interfaces.nsIWebProgressListener.STATE_STOP) ) { - // Some operations including the DOM parsing here - } - } - */ - }); + strings = document.getElementById('wappalyzer-strings'); AddonManager.getAddonByID('wappalyzer@crunchlabz.com', function(addon) { addon.version = addon.version; @@ -65,6 +48,28 @@ // Load content script messageManager.loadFrameScript('chrome://wappalyzer/content/js/content.js', true); + gBrowser.addProgressListener({ + // Listen for location changes + onLocationChange: function(progress, request, location, flags) { + w.adapter.displayApps(); + }, + + // Get response headers + onStateChange: function(progress, request, flags, status) { + if ( flags & Components.interfaces.nsIWebProgressListener.STATE_STOP ) { + var headers = new Object(); + + request.nsIHttpChannel.visitResponseHeaders(function(header, value) { + headers[header] = value; + }); + + w.analyze(progress.currentURI.host, progress.currentURI.spec, { headers: headers }); + } + } + }); + + gBrowser.tabContainer.addEventListener('TabSelect', w.adapter.displayApps, false); + callback(); }); }; @@ -75,17 +80,15 @@ /** * Display apps */ - displayApps: function(args) { - var browser = gBrowser.getBrowserForTab(gBrowser.selectedTab); + displayApps: function() { + var url = gBrowser.currentURI.spec; - url = browser.currentURI.spec; + $('#wappalyzer-menu > menuitem, #wappalyzer-menu > menuseparator').remove(); - if ( args.apps ) { + if ( w.detected[url] != null && w.detected[url].length ) { $('#wappalyzer-icon').attr('src', 'chrome://wappalyzer/skin/images/icon16x16_hot.ico'); - $('#wappalyzer-menu > menuitem, #wappalyzer-menu > menuseparator').remove(); - - args.apps.map(function(app, i) { + w.detected[url].map(function(app, i) { var menuSeparator = $(''); $('#wappalyzer-menu').append(menuSeparator); @@ -119,10 +122,10 @@ var menuItem = $('') .attr('disabled', 'true') - .label('&wappalyzer.noAppsDetected') + .attr('label', strings.getString('wappalyzer.noAppsDetected')) ; - $('#wappalyzer-menu').html(menuItem); + $('#wappalyzer-menu').append(menuItem); } }, diff --git a/adapters/firefox/content/xul/wappalyzer.xul b/adapters/firefox/content/xul/wappalyzer.xul index cd92cc7bb..2c5e9c915 100755 --- a/adapters/firefox/content/xul/wappalyzer.xul +++ b/adapters/firefox/content/xul/wappalyzer.xul @@ -20,7 +20,15 @@ - + + + + + + + + + diff --git a/adapters/firefox/locale/en-US/wappalyzer.dtd b/adapters/firefox/locale/en-US/wappalyzer.dtd index 1a9737e5e..6cbc2a825 100755 --- a/adapters/firefox/locale/en-US/wappalyzer.dtd +++ b/adapters/firefox/locale/en-US/wappalyzer.dtd @@ -1,5 +1,11 @@ - + + + + + + + diff --git a/adapters/firefox/locale/en-US/wappalyzer.properties b/adapters/firefox/locale/en-US/wappalyzer.properties index 1bbd57974..f78b305fa 100755 --- a/adapters/firefox/locale/en-US/wappalyzer.properties +++ b/adapters/firefox/locale/en-US/wappalyzer.properties @@ -1 +1,2 @@ -wappalyzer.name = Wappalyzer +wappalyzer.name = Wappalyzer +wappalyzer.noAppsDetected = No applications detected diff --git a/share/js/wappalyzer.js b/share/js/wappalyzer.js index 6321e0155..abc06e846 100644 --- a/share/js/wappalyzer.js +++ b/share/js/wappalyzer.js @@ -197,7 +197,7 @@ var wappalyzer = wappalyzer || (function() { delete apps, data; } - adapter('displayApps', { url: url, apps: w.detected[url] }); + adapter('displayApps'); } };