import { MessageTypes } from "./types" ; const sendSnowStatus = ( snowing ) => { const message = { type : "SNOW_STATUS" , snowing } ; chrome . runtime . sendMessage ( message ) ; chrome . tabs . query ( { } , ( tabs ) => { tabs . forEach ( ( tab ) => { if ( tab . id ) { chrome . tabs . sendMessage ( tab . id , message ) ; } } ) ; } ) ; } ; let snowing = false ; chrome . storage . local . get ( "snowing" , ( res ) => { if ( res [ "snowing" ] ) { snowing = true ; } else { snowing = false ; } } ) ; chrome . runtime . onMessage . addListener ( ( message ) => { switch ( message . type ) { case "REQ_SNOW_STATUS" : sendSnowStatus ( snowing ) ; break ; case "TOGGLE_SNOW" : snowing = message . snowing ; chrome . storage . local . set ( { snowing : snowing } ) ; sendSnowStatus ( snowing ) ; break ; default : break ; } } ) ;