From 758afea8e321cb24e94f26829081095c96850b7f Mon Sep 17 00:00:00 2001 From: foobar Date: Sat, 13 Oct 2012 18:21:50 +1100 Subject: [PATCH] Apps.js to JSON --- drivers/chrome/background.html | 1 - drivers/chrome/js/driver.js | 26 +++++++++++++++++++++----- drivers/chrome/popup.html | 1 - drivers/firefox/content/js/driver.js | 3 +-- share/js/wappalyzer.js | 21 ++++++++++++++++----- 5 files changed, 38 insertions(+), 14 deletions(-) diff --git a/drivers/chrome/background.html b/drivers/chrome/background.html index 5707e2cd0..b273a4360 100644 --- a/drivers/chrome/background.html +++ b/drivers/chrome/background.html @@ -6,7 +6,6 @@ - diff --git a/drivers/chrome/js/driver.js b/drivers/chrome/js/driver.js index 6d867372c..8115396d5 100644 --- a/drivers/chrome/js/driver.js +++ b/drivers/chrome/js/driver.js @@ -23,6 +23,22 @@ chrome.browserAction.setBadgeBackgroundColor({ color: [255, 102, 0, 255] }); + // Load apps.json + var xhr = new XMLHttpRequest(); + + xhr.open('GET', 'apps.json', true); + + xhr.overrideMimeType('application/json'); + + xhr.onload = function() { + var json = JSON.parse(xhr.responseText); + + w.categories = json.categories; + w.apps = json.apps; + }; + + xhr.send(null); + // Version check try { var version = chrome.app.getDetails().version; @@ -145,17 +161,17 @@ ping: function() { if ( Object.keys(w.ping.hostnames).length && localStorage['tracking'] ) { // Make POST request - var request = new XMLHttpRequest(); + var xhr = new XMLHttpRequest(); - request.open('POST', w.config.websiteURL + 'ping/', true); + xhr.open('POST', w.config.websiteURL + 'ping/', true); - request.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); + xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); - request.onreadystatechange = function(e) { + xhr.onreadystatechange = function(e) { if ( request.readyState == 4 ) { w.log('w.driver.ping: status ' + request.status); } }; - request.send('json=' + encodeURIComponent(JSON.stringify(w.ping))); + xhr.send('json=' + encodeURIComponent(JSON.stringify(w.ping))); w.log('w.driver.ping: ' + JSON.stringify(w.ping)); diff --git a/drivers/chrome/popup.html b/drivers/chrome/popup.html index b96c8826b..d23d6aa0d 100644 --- a/drivers/chrome/popup.html +++ b/drivers/chrome/popup.html @@ -10,7 +10,6 @@ - diff --git a/drivers/firefox/content/js/driver.js b/drivers/firefox/content/js/driver.js index 194491a28..685a3e5ed 100644 --- a/drivers/firefox/content/js/driver.js +++ b/drivers/firefox/content/js/driver.js @@ -40,12 +40,11 @@ // Read apps.json var xhr = Cc['@mozilla.org/xmlextras/xmlhttprequest;1'].createInstance(Ci.nsIXMLHttpRequest); - //xhr.overrideMimeType('text/plain'); xhr.overrideMimeType('application/json'); xhr.open('GET', 'chrome://wappalyzer/content/apps.json', true); - xhr.onload = function(e) { + xhr.onload = function() { var json = JSON.parse(xhr.responseText); w.categories = json.categories; diff --git a/share/js/wappalyzer.js b/share/js/wappalyzer.js index 27542339a..18ff747bc 100644 --- a/share/js/wappalyzer.js +++ b/share/js/wappalyzer.js @@ -105,17 +105,24 @@ var wappalyzer = wappalyzer || (function() { if ( data ) { for ( app in w.apps ) { for ( type in w.apps[app] ) { - if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected + // Skip if the app has already been detected + if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { + continue; + } switch ( type ) { case 'url': - if ( w.apps[app].url.test(url) ) { apps.push(app); } + regex = new RegExp(w.apps[app][type], 'i'); + + if ( regex.test(url) ) { apps.push(app); } break; case 'html': if ( data[type] == null ) { break; } - if ( w.apps[app][type].test(data[type]) ) { apps.push(app); } + regex = new RegExp(w.apps[app][type], 'i'); + + if ( regex.test(data[type]) ) { apps.push(app); } break; case 'script': @@ -156,7 +163,9 @@ var wappalyzer = wappalyzer || (function() { if ( data[type] == null ) { break; } for ( header in w.apps[app].headers ) { - if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) { + regex = new RegExp(w.apps[app][type][header], 'i'); + + if ( data[type][header] != null && regex.test(data[type][header]) ) { apps.push(app); break; @@ -167,8 +176,10 @@ var wappalyzer = wappalyzer || (function() { case 'env': if ( data[type] == null ) { break; } + regex = RegExp(w.apps[app][type], 'i'); + for ( i in data[type] ) { - if ( w.apps[app][type].test(data[type][i]) ) { + if ( regex.test(data[type][i]) ) { apps.push(app); break;