@ -24,6 +24,26 @@
console . log ( '[wappalyzer ' + args . type + '] ' + args . message ) ;
} ,
/ * *
* Get a value from localStorage
* /
getOption : function ( name , defaultValue , callback ) {
browser . storage . local . get ( name ) . then ( function ( item ) {
callback ( item . hasOwnProperty ( name ) ? item [ name ] : defaultValue ) ;
} ) ;
} ,
/ * *
* Set a value in localStorage
* /
setOption : function ( name , value ) {
var option = { } ;
option [ name ] = value ;
browser . storage . local . set ( option ) ;
} ,
/ * *
* Initialize
* /
@ -54,19 +74,27 @@
try {
var version = browser . runtime . getManifest ( ) . version ;
if ( localStorage [ 'version' ] == null ) {
firstRun = true ;
// Set defaults
for ( var option in defaults ) {
localStorage [ option ] = defaults [ option ] ;
w . driver . getOption ( 'version' , null , function ( previousVersion ) {
if ( previousVersion === null ) {
w . driver . goToURL ( {
url : w . config . websiteURL + 'installed'
} ) ;
} else if ( version !== previousVersion ) {
w . driver . getOption ( 'upgradeMessage' , true , function ( upgradeMessage ) {
if ( upgradeMessage ) {
w . driver . goToURL ( {
url : w . config . websiteURL + 'upgraded' ,
background : true
} ) ;
}
} else if ( version !== localStorage [ 'version' ] && parseInt ( localStorage [ 'upgradeMessage' ] , 10 ) ) {
upgraded = true ;
} ) ;
}
localStorage [ 'version' ] = version ;
} catch ( e ) { }
w . driver . setOption ( 'version' , version ) ;
} ) ;
} catch ( e ) {
// Do nothing
}
if ( typeof chrome === 'undefined' ) {
browser . runtime . onMessage . addListener ( w . driver . onMessage ) ;
@ -183,10 +211,14 @@
} ,
/ * *
* Open a tab
* /
goToURL : function ( args ) {
var url = args . url + ( typeof args . medium === 'undefined' ? '' : '?pk_campaign=chrome&pk_kwd=' + args . medium ) ;
browser . tabs . create ( { url : url , active : args . background === undefined || ! args . background } ) ;
browser . tabs . create ( {
url : args . url ,
active : args . background === undefined || ! args . background
} ) ;
} ,
/ * *
@ -208,24 +240,28 @@
tabCache [ tab . id ] . appsDetected = w . detected [ url ] ;
if ( count > 0 ) {
// Find the main application to display
w . driver . getOption ( 'dynamicIcon' , true , function ( dynamicIcon ) {
var appName , found = false ;
// Find the main application to display
w . driver . categoryOrder . forEach ( function ( match ) {
for ( appName in w . detected [ url ] ) {
w . apps [ appName ] . cats . forEach ( function ( cat ) {
var icon = w . apps [ appName ] . icon || 'default.svg' ;
if ( ! parseInt ( localStorage[ ' dynamicIcon'] , 10 ) ) {
if ( ! dynamicIcon ) {
icon = 'default.svg' ;
}
if ( cat == match && ! found ) {
if ( cat = == match && ! found ) {
if ( /\.svg$/i . test ( icon ) ) {
icon = 'converted/' + icon + '.png' ;
}
browser . pageAction . setIcon ( { tabId : tab . id , path : 'images/icons/' + icon } ) ;
browser . pageAction . setIcon ( {
tabId : tab . id ,
path : 'images/icons/' + icon
} ) ;
found = true ;
}
@ -239,6 +275,7 @@
} else {
browser . pageAction . show ( tab . id ) ;
}
} ) ;
} ;
} ,
@ -246,7 +283,8 @@
* Anonymously track detected applications for research purposes
* /
ping : function ( ) {
if ( Object . keys ( w . ping . hostnames ) . length && parseInt ( localStorage [ 'tracking' ] , 10 ) ) {
w . driver . getOption ( 'tracking' , true , function ( tracking ) {
if ( Object . keys ( w . ping . hostnames ) . length && tracking ) {
w . driver . post ( 'http://ping.wappalyzer.com/v2/' , w . ping ) ;
w . log ( 'w.driver.ping: ' + JSON . stringify ( w . ping ) ) ;
@ -257,6 +295,7 @@
w . adCache = [ ] ;
}
} ) ;
} ,
/ * *