import { ChromeLocalStorage , ChromeStorage , ChromeSyncStorage } from './types' ; interface Classlist { toggle ( this , c ) : HTMLElement ; add ( this , c ) : HTMLElement ; remove ( this , c ) : HTMLElement ; } function chainableClassList ( element ) { const { classList } = element ; return { toggle : function toggle ( c ) { classList . toggle ( c ) ; return this ; } , add : function add ( c ) { classList . add ( c ) ; return this ; } , remove : function remove ( c ) { classList . remove ( c ) ; return this ; } , } ; } const $ = document . getElementById . bind ( document ) ; function removeChildElements ( element ) { while ( element . hasChildNodes ( ) ) { if ( element . lastChild ) element . removeChild ( element . lastChild ) ; } } function validateResponse ( response ) { if ( ! response . ok ) { throw Error ( response . statusText ) ; } return response ; } function lessThanTimeAgo ( timestamp = Date . now ( ) , timeInSeconds ) { const timeInMilliseconds = 1000 * timeInSeconds ; const timeAgo = Date . now ( ) - timeInMilliseconds ; return timestamp > timeAgo ; } async function getFromChromeLocalStorage ( keys ) { return new Promise ( ( resolve , reject ) => { chrome . storage . local . get ( keys , ( result ) => { if ( chrome . runtime . lastError ) { reject ( chrome . runtime . lastError . message ) ; } else { resolve ( result ) ; } } ) ; } ) ; } async function getFromChromeSyncStorage ( keys ) { return new Promise ( ( resolve , reject ) => { chrome . storage . sync . get ( keys , ( result ) => { if ( chrome . runtime . lastError ) { reject ( chrome . runtime . lastError . message ) ; } else { resolve ( result ) ; } } ) ; } ) ; } async function getChromeStorageData ( ) { const localData = await getFromChromeLocalStorage ( null ) ; const syncData = await getFromChromeSyncStorage ( null ) ; return Object . assign ( syncData , localData ) ; } export { chainableClassList , $ , removeChildElements , validateResponse , lessThanTimeAgo , getFromChromeLocalStorage , getFromChromeSyncStorage , getChromeStorageData , } ;