Show app on mouseover

Show app on mouseover
Reduce dependency with jQuery
main
Camille Barneaud 12 years ago
parent 961bcc015f
commit f85176f3a4

@ -1,342 +1,321 @@
/** /**
* Firefox driver * Firefox driver
*/ */
(function() { (function() {
//'use strict'; //'use strict';
if ( wappalyzer == null ) return; if ( wappalyzer == null ) return;
var w = wappalyzer, prefs, strings, $; var w = wappalyzer, prefs, strings, $;
const const
Cc = Components.classes, Cc = Components.classes,
Ci = Components.interfaces Ci = Components.interfaces
; ;
w.driver = { w.driver = {
lastDisplayed: null, lastDisplayed: null,
/** /**
* Log messages to console * Log messages to console
*/ */
log: function(args) { log: function(args) {
if ( prefs != null && prefs.getBoolPref('debug') ) { if ( prefs != null && prefs.getBoolPref('debug') ) {
Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService).logStringMessage(args.message); Cc['@mozilla.org/consoleservice;1'].getService(Ci.nsIConsoleService).logStringMessage(args.message);
} }
}, },
/** /**
* Initialize * Initialize
*/ */
init: function(callback) { init: function(callback) {
var handler = function() { var handler = function() {
window.removeEventListener('load', handler, false); window.removeEventListener('load', handler, false);
w.log('w.driver: browser window loaded'); w.log('w.driver: browser window loaded');
strings = document.getElementById('wappalyzer-strings'); strings = document.getElementById('wappalyzer-strings');
// Read apps.json // Read apps.json
var xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Ci.nsIXMLHttpRequest); var xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Ci.nsIXMLHttpRequest);
xhr.overrideMimeType('application/json'); xhr.overrideMimeType('application/json');
xhr.open('GET', 'chrome://wappalyzer/content/apps.json', true); xhr.open('GET', 'chrome://wappalyzer/content/apps.json', true);
xhr.onload = function() { xhr.onload = function() {
var json = JSON.parse(xhr.responseText); var json = JSON.parse(xhr.responseText);
w.categories = json.categories; w.categories = json.categories;
w.apps = json.apps; w.apps = json.apps;
}; };
xhr.send(null); xhr.send(null);
AddonManager.getAddonByID('wappalyzer@crunchlabz.com', function(addon) { AddonManager.getAddonByID('wappalyzer@crunchlabz.com', function(addon) {
// Load jQuery // Load jQuery
Cc['@mozilla.org/moz/jssubscript-loader;1'].getService(Ci.mozIJSSubScriptLoader).loadSubScript('chrome://wappalyzer/content/js/lib/jquery.min.js'); Cc['@mozilla.org/moz/jssubscript-loader;1'].getService(Ci.mozIJSSubScriptLoader).loadSubScript('chrome://wappalyzer/content/js/lib/jquery.min.js');
$ = jQuery; $ = jQuery;
jQuery.noConflict(true); jQuery.noConflict(true);
// Preferences // Preferences
prefs = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefService).getBranch('extensions.wappalyzer.'); prefs = Cc['@mozilla.org/preferences-service;1'].getService(Ci.nsIPrefService).getBranch('extensions.wappalyzer.');
prefs.addObserver('', w.driver, false); prefs.addObserver('', w.driver, false);
container(); container();
bindings(); bindings();
// Version check // Version check
addon.version = addon.version; addon.version = addon.version;
if ( !prefs.getCharPref('version') ) { if ( !prefs.getCharPref('version') ) {
w.config.firstRun = true; w.config.firstRun = true;
} else if ( prefs.getCharPref('version') != addon.version ) { } else if ( prefs.getCharPref('version') != addon.version ) {
w.config.upgraded = true; w.config.upgraded = true;
} }
prefs.setCharPref('version', addon.version); prefs.setCharPref('version', addon.version);
// Listen for messages from content script // Listen for messages from content script
messageManager.addMessageListener('wappalyzer', content); messageManager.addMessageListener('wappalyzer', content);
// Load content script // Load content script
messageManager.loadFrameScript('chrome://wappalyzer/content/js/content.js', true); messageManager.loadFrameScript('chrome://wappalyzer/content/js/content.js', true);
gBrowser.addProgressListener({ gBrowser.addProgressListener({
// Listen for location changes // Listen for location changes
onLocationChange: function(progress, request, location, flags) { onLocationChange: function(progress, request, location, flags) {
w.driver.displayApps(); w.driver.displayApps();
}, },
// Get response headers // Get response headers
onStateChange: function(progress, request, flags, status) { onStateChange: function(progress, request, flags, status) {
if ( !prefs.getBoolPref('analyzeHeaders') ) { return; } if ( !prefs.getBoolPref('analyzeHeaders') ) { return; }
if ( request != null && flags & Ci.nsIWebProgressListener.STATE_STOP ) { if ( request != null && flags & Ci.nsIWebProgressListener.STATE_STOP ) {
if ( request.nsIHttpChannel && request.contentType == 'text/html' ) { if ( request.nsIHttpChannel && request.contentType == 'text/html' ) {
if ( progress.currentURI && request.name == progress.currentURI.spec ) { if ( progress.currentURI && request.name == progress.currentURI.spec ) {
var headers = new Object(); var headers = new Object();
request.nsIHttpChannel.visitResponseHeaders(function(header, value) { request.nsIHttpChannel.visitResponseHeaders(function(header, value) {
headers[header] = value; headers[header] = value;
}); });
w.analyze(progress.currentURI.host, progress.currentURI.spec, { headers: headers }); w.analyze(progress.currentURI.host, progress.currentURI.spec, { headers: headers });
} }
} }
} }
} }
}); });
gBrowser.tabContainer.addEventListener('TabSelect', w.driver.displayApps, false); gBrowser.tabContainer.addEventListener('TabSelect', w.driver.displayApps, false);
callback(); callback();
}); });
}; };
window.addEventListener('load', handler, false); window.addEventListener('load', handler, false);
window.addEventListener('unload', w.driver.track, false); window.addEventListener('unload', w.driver.track, false);
}, },
// Observe preference changes // Observe preference changes
observe: function(subject, topic, data) { observe: function(subject, topic, data) {
if ( topic != 'nsPref:changed' ) { return; } if ( topic != 'nsPref:changed' ) { return; }
switch(data) { switch(data) {
case 'addonBar': case 'addonBar':
container(); container();
break; break;
} }
w.driver.displayApps(); w.driver.displayApps();
}, },
/** /**
* Display apps * Display apps
*/ */
displayApps: function() { displayApps: function() {
var menuItem, menuSeparator, image, url = gBrowser.currentURI.spec.split('#')[0]; var menuItem, menuSeparator, image, url = gBrowser.currentURI.spec.split('#')[0];
if ( w.detected[url] != null && w.detected[url].length ) { if ( w.detected[url] != null && w.detected[url].length ) {
// No change // No change
if ( w.driver.lastDisplayed === JSON.stringify(w.detected[url]) ) { return; } if ( w.driver.lastDisplayed === JSON.stringify(w.detected[url]) ) { return; }
} else { } else {
if ( w.driver.lastDisplayed === 'empty' ) { return; } if ( w.driver.lastDisplayed === 'empty' ) { return; }
} }
$('#wappalyzer-container > image, #wappalyzer-menu > menuitem, #wappalyzer-menu > menuseparator').attr('class', 'wappalyzer-remove'); $('#wappalyzer-container > image, #wappalyzer-menu > menuitem, #wappalyzer-menu > menuseparator').attr('class', 'wappalyzer-remove');
if ( w.detected[url] != null && w.detected[url].length ) { if ( w.detected[url] != null && w.detected[url].length ) {
if ( !prefs.getBoolPref('showIcons') ) { if ( !prefs.getBoolPref('showIcons') ) {
image = $('<image/>').attr('src', 'chrome://wappalyzer/skin/images/icon_hot.png'); $('<image>').attr('src', 'chrome://wappalyzer/skin/images/icon_hot.png').prependTo(document.getElementById('wappalyzer-container'));
}
$('#wappalyzer-container').prepend(image);
} w.detected[url].map(function(app, i) {
var j, cat, showCat;
w.detected[url].map(function(app, i) {
var j, cat, showCat; for ( i in w.apps[app].cats ) {
showCat = false;
for ( i in w.apps[app].cats ) {
showCat = false; try {
showCat = prefs.getBoolPref('cat' + w.apps[app].cats[i]);
try { } catch(e) { }
showCat = prefs.getBoolPref('cat' + w.apps[app].cats[i]);
} catch(e) { } if ( showCat ) {
if ( prefs.getBoolPref('showIcons') ) {
if ( showCat ) { $('<image>').attr('src', 'chrome://wappalyzer/skin/images/icons/' + app + '.png').attr('tooltiptext', app + ' - ' + strings.getString('wappalyzer.cat' + w.apps[app].cats[i])).prependTo(document.getElementById('wappalyzer-container'));
if ( prefs.getBoolPref('showIcons') ) { }
image = $('<image/>').attr('src', 'chrome://wappalyzer/skin/images/icons/' + app + '.png');
$('<menuseparator>').appendTo(document.getElementById('wappalyzer-menu'));
$('#wappalyzer-container').prepend(image);
} $('#wappalyzer-menu')
.append($('<menuitem>')
menuSeparator = $('<menuseparator/>'); .attr('class', 'wappalyzer-application menuitem-iconic')
.attr('image', 'chrome://wappalyzer/skin/images/icons/' + app + '.png')
$('#wappalyzer-menu').append(menuSeparator); .attr('label', app)
.attr('name', app)
menuItem = $('<menuitem/>') .on('command', function() {
.attr('class', 'wappalyzer-application menuitem-iconic') w.driver.goToURL({ url: w.config.websiteURL + 'applications/' + app.toLowerCase().replace(/ /g, '-').replace(/[^\w-]/g, '') });
.attr('image', 'chrome://wappalyzer/skin/images/icons/' + app + '.png') }));
.attr('label', app)
; for ( j in w.apps[app].cats ) {
var cat = w.apps[app].cats[j];
menuItem.bind('command', function() {
w.driver.goToURL({ url: w.config.websiteURL + 'applications/' + app.toLowerCase().replace(/ /g, '-').replace(/[^\w-]/g, '') }); $('#wappalyzer-menu')
}); .append($('<menuitem>')
.attr('class', 'wappalyzer-category')
$('#wappalyzer-menu').append(menuItem); .attr('label', strings.getString('wappalyzer.cat' + cat))
.on('command', function() {
for ( j in w.apps[app].cats ) { w.driver.goToURL({ url: w.config.websiteURL + 'categories/' + w.categories[cat] });
var cat = w.apps[app].cats[j]; }));
}
menuItem = $('<menuitem/>')
.attr('class', 'wappalyzer-category') break;
.attr('label', strings.getString('wappalyzer.cat' + cat)) }
; }
});
menuItem.bind('command', function() {
w.driver.goToURL({ url: w.config.websiteURL + 'categories/' + w.categories[cat] }); w.driver.lastDisplayed = JSON.stringify(w.detected[url]);
}); } else {
$('<image>')
$('#wappalyzer-menu').append(menuItem); .attr('src', 'chrome://wappalyzer/skin/images/icon.png')
} .prependTo(document.getElementById('wappalyzer-container'));
break; $('<menuseparator>').appendTo(document.getElementById('wappalyzer-menu'));
}
} $('<menuitem>')
}); .attr('disabled', 'true')
.attr('label', strings.getString('wappalyzer.noAppsDetected'))
w.driver.lastDisplayed = JSON.stringify(w.detected[url]); .appendTo(document.getElementById('wappalyzer-menu'));
} else {
image = $('<image/>').attr('src', 'chrome://wappalyzer/skin/images/icon.png'); w.driver.lastDisplayed = 'empty';
}
$('#wappalyzer-container').prepend(image);
$('.wappalyzer-remove').remove();
menuSeparator = $('<menuseparator/>'); },
$('#wappalyzer-menu').append(menuSeparator); /**
* Go to URL
menuItem = $('<menuitem/>') */
.attr('disabled', 'true') goToURL: function(args) {
.attr('label', strings.getString('wappalyzer.noAppsDetected')) gBrowser.selectedTab = gBrowser.addTab(args.url + '?utm_source=firefox&utm_medium=extension&utm_campaign=extensions');
; },
$('#wappalyzer-menu').append(menuItem); /**
* Anonymously track detected applications for research purposes
w.driver.lastDisplayed = 'empty'; */
} ping: function() {
if ( Object.keys(w.ping.hostnames).length && prefs.getBoolPref('tracking') ) {
$('.wappalyzer-remove').remove(); // Make POST request
}, var request = new XMLHttpRequest();
/** request.open('POST', w.config.websiteURL + 'ping/', true);
* Go to URL
*/ request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
goToURL: function(args) {
gBrowser.selectedTab = gBrowser.addTab(args.url + '?utm_source=firefox&utm_medium=extension&utm_campaign=extensions'); request.onreadystatechange = function(e) {
}, if ( request.readyState == 4 ) { w.log('w.driver.ping: status ' + request.status); }
};
/**
* Anonymously track detected applications for research purposes request.send('json=' + encodeURIComponent(JSON.stringify(w.ping)));
*/
ping: function() { w.log('w.driver.ping: ' + JSON.stringify(w.ping));
if ( Object.keys(w.ping.hostnames).length && prefs.getBoolPref('tracking') ) {
// Make POST request w.ping = {};
var request = new XMLHttpRequest(); }
}
request.open('POST', w.config.websiteURL + 'ping/', true); };
request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); /**
* Content message listener
request.onreadystatechange = function(e) { */
if ( request.readyState == 4 ) { w.log('w.driver.ping: status ' + request.status); } function content(msg) {
}; w.log('content.js');
request.send('json=' + encodeURIComponent(JSON.stringify(w.ping))); switch ( msg.json.action ) {
case 'analyze':
w.log('w.driver.ping: ' + JSON.stringify(w.ping)); w.analyze(msg.json.hostname, msg.json.url, msg.json.analyze);
w.ping = {}; break;
} case 'get prefs':
} return {
}; analyzeJavaScript: prefs.getBoolPref('analyzeJavaScript'),
analyzeOnLoad: prefs.getBoolPref('analyzeOnLoad')
/** };
* Content message listener
*/ break;
function content(msg) { }
w.log('content.js');
msg = null;
switch ( msg.json.action ) { }
case 'analyze':
w.analyze(msg.json.hostname, msg.json.url, msg.json.analyze); /**
* Move container to address or addon bar
break; */
case 'get prefs': function container() {
return { if ( prefs.getBoolPref('addonBar') ) {
analyzeJavaScript: prefs.getBoolPref('analyzeJavaScript'), $('#wappalyzer-container').prependTo(document.getElementById('wappalyzer-addonbar'));
analyzeOnLoad: prefs.getBoolPref('analyzeOnLoad')
}; } else {
$('#wappalyzer-container').prependTo(document.getElementById('urlbar-icons'));
break;
} $('#wappalyzer-addonbar').attr('collapsed', 'true');
}
msg = null; }
}
/**
/** * Bindings
* Move container to address or addon bar */
*/ function bindings() {
function container() { // Menu items
if ( prefs.getBoolPref('addonBar') ) { var prefix = 'wappalyzer-menu-';
$('#wappalyzer-container').prependTo($('#wappalyzer-addonbar'));
document.getElementById(prefix + 'preferences').onclick = function() {
$('#wappalyzer-addonbar').attr('collapsed', 'false'); w.driver.goToURL({ url: 'chrome://wappalyzer/content/xul/preferences.xul' })
} else { };
$('#wappalyzer-container').prependTo($('#urlbar-icons'));
document.getElementById(prefix + 'feedback').onclick = function() {
$('#wappalyzer-addonbar').attr('collapsed', 'true'); w.driver.goToURL({ url: w.config.websiteURL + 'contact' })
} };
}
document.getElementById(prefix + 'website').onclick = function() {
/** w.driver.goToURL({ url: w.config.websiteURL })
* Bindings };
*/
function bindings() { document.getElementById(prefix + 'github').onclick = function() {
// Menu items w.driver.goToURL({ url: w.config.githubURL })
var prefix = '#wappalyzer-menu-'; };
$(prefix + 'preferences' ) document.getElementById(prefix + 'twitter').onclick = function() {
.bind('command', function() { w.driver.goToURL({ url: w.config.twitterURL })
w.driver.goToURL({ url: 'chrome://wappalyzer/content/xul/preferences.xul' }) };
}); }
$(prefix + 'feedback') w.init();
.bind('command', function() { })();
w.driver.goToURL({ url: w.config.websiteURL + 'contact' })
});
$(prefix + 'website')
.bind('command', function() {
w.driver.goToURL({ url: w.config.websiteURL })
});
$(prefix + 'github' )
.bind('command', function() {
w.driver.goToURL({ url: w.config.githubURL })
});
$(prefix + 'twitter')
.bind('command', function() {
w.driver.goToURL({ url: w.config.twitterURL})
});
}
w.init();
})();

Loading…
Cancel
Save