declare var browser ; window . browser = ( function ( ) { return ( window . msBrowser || window . browser || window . chrome ) ; } ) ( ) ; let settings = { active : true , } ; browser . storage . local . get ( [ "settings" ] , function ( result ) { if ( result && result . settings ) { settings = result . settings ; } browser . browserAction . onClicked . addListener ( function ( tab ) { settings . active = ! settings . active ; update ( ) ; } ) ; browser . tabs . onUpdated . addListener ( function ( tabId , info , tab ) { if ( info . status === "complete" && settings . active === true ) { browser . tabs . sendMessage ( tabId , { action : "inject-editor" , } ) ; } } . bind ( this ) ) ; update ( ) ; } ) ; function update ( ) { updateActiveIcon ( settings . active ) ; browser . storage . local . set ( { settings : settings } ) ; } function updateActiveIcon ( state ) { if ( state ) { browser . browserAction . setIcon ( { path : "icons/on-32.png" } ) ; } else { browser . browserAction . setIcon ( { path : "icons/off-32.png" } ) ; } }