From 00241871a99a2d1b1eae10586bf981ebf24867e3 Mon Sep 17 00:00:00 2001 From: ElbertF Date: Tue, 27 Dec 2011 10:39:29 +1100 Subject: [PATCH] Added Firefox preferences --- adapters/firefox/content/js/adapter.js | 167 +++++++++++++++--- adapters/firefox/content/js/options.js | 19 -- .../xul/{options.xul => categories.xul} | 147 +++------------ adapters/firefox/content/xul/wappalyzer.xul | 28 ++- .../firefox/defaults/preferences/defaults.js | 64 ++++--- adapters/firefox/install.rdf | 2 + adapters/firefox/locale/en-US/wappalyzer.dtd | 69 ++++---- adapters/firefox/skin/css/wappalyzer.css | 9 + adapters/firefox/skin/images/gplus.ico | Bin 0 -> 22382 bytes share/images/donate.png | Bin 0 -> 714 bytes share/images/feedback.png | Bin 0 -> 782 bytes share/images/github.ico | Bin 0 -> 1150 bytes share/images/options.png | Bin 0 -> 610 bytes share/images/twitter.ico | Bin 0 -> 1150 bytes share/js/wappalyzer.js | 1 + 15 files changed, 271 insertions(+), 235 deletions(-) delete mode 100644 adapters/firefox/content/js/options.js rename adapters/firefox/content/xul/{options.xul => categories.xul} (53%) create mode 100644 adapters/firefox/skin/images/gplus.ico create mode 100644 share/images/donate.png create mode 100644 share/images/feedback.png create mode 100644 share/images/github.ico create mode 100644 share/images/options.png create mode 100644 share/images/twitter.ico diff --git a/adapters/firefox/content/js/adapter.js b/adapters/firefox/content/js/adapter.js index efddd488f..46347c6e8 100644 --- a/adapters/firefox/content/js/adapter.js +++ b/adapters/firefox/content/js/adapter.js @@ -7,16 +7,18 @@ var w = wappalyzer; - var $, strings; + var $, prefs, strings; w.adapter = { /** * Log messages to console */ log: function(args) { - var consoleService = Components.classes["@mozilla.org/consoleservice;1"].getService(Components.interfaces.nsIConsoleService); + if ( prefs != null && prefs.getBoolPref('debug') ) { + var consoleService = Components.classes['@mozilla.org/consoleservice;1'].getService(Components.interfaces.nsIConsoleService); - consoleService.logStringMessage(args.message); + consoleService.logStringMessage(args.message); + } }, /** @@ -31,8 +33,6 @@ strings = document.getElementById('wappalyzer-strings'); AddonManager.getAddonByID('wappalyzer@crunchlabz.com', function(addon) { - addon.version = addon.version; - // Load jQuery (function () { var window; @@ -42,6 +42,22 @@ $ = jQuery.noConflict(true); })(); + // Preferences + prefs = Components.classes['@mozilla.org/preferences-service;1'].getService(Components.interfaces.nsIPrefService).getBranch('extensions.wappalyzer.'); + + container(); + + // Version check + addon.version = addon.version; + + if ( !prefs.getCharPref('version') ) { + w.config.firstRun = true; + } else if ( prefs.getCharPref('version') != addon.version ) { + w.config.upgraded = true; + } + + prefs.setCharPref('version', addon.version); + // Listen for messages from content script messageManager.addMessageListener('wappalyzer', content); @@ -56,7 +72,7 @@ // Get response headers onStateChange: function(progress, request, flags, status) { - if ( flags & Components.interfaces.nsIWebProgressListener.STATE_STOP ) { + if ( request.nsIHttpChannel != null && flags & Components.interfaces.nsIWebProgressListener.STATE_STOP ) { var headers = new Object(); request.nsIHttpChannel.visitResponseHeaders(function(header, value) { @@ -83,38 +99,68 @@ displayApps: function() { var url = gBrowser.currentURI.spec; - $('#wappalyzer-menu > menuitem, #wappalyzer-menu > menuseparator').remove(); + $('#wappalyzer-container > image, #wappalyzer-menu > menuitem, #wappalyzer-menu > menuseparator').remove(); if ( w.detected[url] != null && w.detected[url].length ) { - $('#wappalyzer-icon').attr('src', 'chrome://wappalyzer/skin/images/icon16x16_hot.ico'); + if ( !prefs.getBoolPref('showIcons') ) { + var image = $('') + .attr('src', 'chrome://wappalyzer/skin/images/icon16x16_hot.ico') + ; + + $('#wappalyzer-container').prepend(image); + } w.detected[url].map(function(app, i) { - var menuSeparator = $(''); + var display = false; - $('#wappalyzer-menu').append(menuSeparator); + for ( cat in w.apps[app].cats ) { + if ( prefs.getBoolPref('cat' + w.apps[app].cats[cat]) ) { + display = true; - var menuItem = $('') - .attr('image', 'chrome://wappalyzer/skin/images/icons/' + app + '.ico') - .attr('label', app) - ; + break; + } + } - menuItem.bind('command', function() { - w.adapter.goToURL({ url: w.config.websiteURL + 'stats/app/' + escape(app) }); - }); + if ( display ) { + if ( prefs.getBoolPref('showIcons') ) { + var image = $('') + .attr('src', 'chrome://wappalyzer/skin/images/icons/' + app + '.ico') + ; + + $('#wappalyzer-container').prepend(image); + } - $('#wappalyzer-menu').append(menuItem); + var menuSeparator = $(''); + + $('#wappalyzer-menu').append(menuSeparator); - for ( cat in w.apps[app].cats ) { var menuItem = $('') - .attr('disabled', 'true') - .attr('label', w.categories[cat].name) + .attr('image', 'chrome://wappalyzer/skin/images/icons/' + app + '.ico') + .attr('label', app) ; + menuItem.bind('command', function() { + w.adapter.goToURL({ url: w.config.websiteURL + 'stats/app/' + escape(app) }); + }); + $('#wappalyzer-menu').append(menuItem); + + for ( cat in w.apps[app].cats ) { + var menuItem = $('') + .attr('disabled', 'true') + .attr('label', w.categories[w.apps[app].cats[cat]].name) + ; + + $('#wappalyzer-menu').append(menuItem); + } } }); } else { - $('#wappalyzer-icon').attr('src', 'chrome://wappalyzer/skin/images/icon16x16.ico'); + var image = $('') + .attr('src', 'chrome://wappalyzer/skin/images/icon16x16.ico') + ; + + $('#wappalyzer-container').prepend(image); var menuSeparator = $(''); @@ -133,7 +179,7 @@ * Go to URL */ goToURL: function(args) { - gBrowser.addTab(args.url); + gBrowser.selectedTab = gBrowser.addTab(args.url); } }; @@ -148,5 +194,80 @@ delete msg; } + /** + * Move container to address or addon bar + */ + function container() { + $('#wappalyzer-container') + .remove() + .prependTo(prefs.getBoolPref('addonBar') ? $('#wappalyzer-addonbar') : $('#urlbar-icons')); + + // Menu items + var prefix = '#wappalyzer-menu-'; + + $(prefix + 'icons') + .attr('checked', prefs.getBoolPref('showIcons') ? 'true' : 'false') + .bind('command', function() { + prefs.setBoolPref('showIcons', !prefs.getBoolPref('showIcons')); + + $(this).attr('checked', prefs.getBoolPref('showIcons') ? 'true' : 'false'); + + w.adapter.displayApps(); + }); + + $(prefix + 'tracking' ) + .attr('checked', prefs.getBoolPref('tracking') ? 'true' : 'false') + .bind('command', function() { + prefs.setBoolPref('tracking', !prefs.getBoolPref('tracking')); + + $(this).attr('checked', prefs.getBoolPref('tracking') ? 'true' : 'false'); + }); + + $(prefix + 'addonbar' ) + .attr('checked', prefs.getBoolPref('addonBar') ? 'true' : 'false') + .bind('command', function() { + prefs.setBoolPref('addonBar', !prefs.getBoolPref('addonBar')); + + $(this).attr('checked', prefs.getBoolPref('addonBar') ? 'true' : 'false'); + + container(); + }); + + $(prefix + 'categories') + .bind('command', function() { + w.adapter.goToURL({ url: 'chrome://wappalyzer/content/xul/categories.xul' }) + }); + + $(prefix + 'donate') + .bind('command', function() { + w.adapter.goToURL({ url: w.config.websiteURL + 'donate/' }) + }); + + $(prefix + 'feedback') + .bind('command', function() { + w.adapter.goToURL({ url: w.config.websiteURL + '?redirect=feedback' }) + }); + + $(prefix + 'website') + .bind('command', function() { + w.adapter.goToURL({ url: w.config.websiteURL }) + }); + + $(prefix + 'github' ) + .bind('command', function() { + w.adapter.goToURL({ url: w.config.githubURL }) + }); + + $(prefix + 'twitter') + .bind('command', function() { + w.adapter.goToURL({ url: w.config.twitterURL}) + }); + + $(prefix + 'gplus') + .bind('command', function() { + w.adapter.goToURL({ url: w.config.gplusURL }) + }); + } + w.init(); })(); diff --git a/adapters/firefox/content/js/options.js b/adapters/firefox/content/js/options.js deleted file mode 100644 index 292fdcda6..000000000 --- a/adapters/firefox/content/js/options.js +++ /dev/null @@ -1,19 +0,0 @@ -addEventListener('load', function() { - if ( typeof wappalyzer != undefined ) { - var preferences = document.getElementById('wappalyzer-options') - .getElementsByTagName('preferences')[0] - ; - - if ( preferences ) { - for ( i in wappalyzer.cats ) { - var preference = document.createElement('preference'); - - preference.setAttribute('id', 'wappalyzer-cat' + i); - preference.setAttribute('name', 'wappalyzer.cat' + i); - preference.setAttribute('type', 'bool'); - - preferences.appendChild(preference); - } - } - } -}, false); diff --git a/adapters/firefox/content/xul/options.xul b/adapters/firefox/content/xul/categories.xul similarity index 53% rename from adapters/firefox/content/xul/options.xul rename to adapters/firefox/content/xul/categories.xul index 15bd93743..cc6bf18c1 100755 --- a/adapters/firefox/content/xul/options.xul +++ b/adapters/firefox/content/xul/categories.xul @@ -1,103 +1,45 @@ - + - - -