interface Headers { [ s ] : string ; } interface Data { [ s ] : string | Blob ; } export const httpGet = async ( url , headers = { } ) => { return fetch ( url , { headers , credentials : 'include' , } ) ; } ; export const httpPostForm = async ( url , data , headers = { } ) => { const formData = new FormData ( ) ; for ( const key of Object . keys ( data ) ) { formData . append ( key , data [ key ] ) ; } return fetch ( url , { method : 'POST' , headers , credentials : 'include' , body : formData , } ) ; } ; export const getBase64Image = async ( url ) : Promise < Blob > => { return ( await fetch ( url ) ) . blob ( ) ; } ; const convertBlobToBase64 = ( blob ) => { return new Promise < string > ( ( resolve , reject ) => { const reader = new FileReader ( ) ; reader . onerror = reject ; reader . onload = ( ) => resolve ( reader . result as string ) ; reader . readAsDataURL ( blob ) ; } ) ; } ; export const notif = async ( title , message , imageUrl ? ) => { let base64image ; if ( imageUrl ) { const blob = await getBase64Image ( imageUrl ) ; base64image = await convertBlobToBase64 ( blob ) ; } await browser . notifications . create ( `${ Math . random ( ) }` , { type : 'basic' , title , message , iconUrl : base64image , } ) ; } ; export const notifError = async ( ) => { await notif ( browser . runtime . getManifest ( ) . name , browser . i18n . getMessage ( 'error' ) , browser . runtime . getURL ( 'images/icon-128.png' ) ) ; } ; export const isChrome = ( ) => { return process . env . VENDOR == 'chrome' ; } ; export const isFirefox = ( ) => { return process . env . VENDOR == 'firefox' ; } ;