@@ -228,6 +228,58 @@ export const copyStorageToClipboard = (
228228 return false ; // do not expect a response
229229}
230230
231+ const addMessageListener = (
232+ message : IChromeMessage ,
233+ sender : chrome . runtime . MessageSender ,
234+ response : TResponse
235+ ) => {
236+ if ( validateSender ( Sender . Extension , Action . Add , message , sender ) ) {
237+ try {
238+ const itemKey = new Date ( ) . getTime ( ) . toString ( ) ;
239+ sessionStorage . setItem ( itemKey , '{}' ) ;
240+
241+ const data = {
242+ obj : Object . assign ( { } , sessionStorage ) ,
243+ itemKey : itemKey ,
244+ }
245+
246+ response ( { error : null , data : data } ) ;
247+ } catch {
248+ response ( {
249+ error : 'Error adding session storage item' ,
250+ data : null ,
251+ } ) ;
252+ }
253+ return true ; // we will eventually return a response
254+ }
255+ return false ; // do not expect a response
256+ } ;
257+
258+ const deleteMessageListener = (
259+ message : IChromeMessage ,
260+ sender : chrome . runtime . MessageSender ,
261+ response : TResponse
262+ ) => {
263+ if ( validateSender ( Sender . Extension , Action . Delete , message , sender ) ) {
264+ try {
265+ console . log ( 'deleteMessageListener' , message ) ;
266+ message . message ?. data . forEach ( ( k : string ) => {
267+ sessionStorage . removeItem ( k ) ;
268+ } ) ;
269+
270+ const data = Object . assign ( { } , sessionStorage ) ;
271+ response ( { error : null , data : data } ) ;
272+ } catch {
273+ response ( {
274+ error : 'Error adding session storage item' ,
275+ data : null ,
276+ } ) ;
277+ }
278+ return true ; // we will eventually return a response
279+ }
280+ return false ; // do not expect a response
281+ } ;
282+
231283const main = ( ) => {
232284 // prevent duplicate listeners
233285 chrome . runtime . onMessage . removeListener ( requestMessageListener ) ;
@@ -237,6 +289,8 @@ const main = () => {
237289 chrome . runtime . onMessage . removeListener ( fillStorageMessageListener ) ;
238290 chrome . runtime . onMessage . removeListener ( checkReleaseListener ) ;
239291 chrome . runtime . onMessage . removeListener ( copyStorageToClipboard ) ;
292+ chrome . runtime . onMessage . removeListener ( addMessageListener ) ;
293+ chrome . runtime . onMessage . removeListener ( deleteMessageListener ) ;
240294
241295 // Fired when a message is sent from either an extension process or a content script.
242296 chrome . runtime . onMessage . addListener ( requestMessageListener ) ;
@@ -246,6 +300,8 @@ const main = () => {
246300 chrome . runtime . onMessage . addListener ( fillStorageMessageListener ) ;
247301 chrome . runtime . onMessage . addListener ( checkReleaseListener ) ;
248302 chrome . runtime . onMessage . addListener ( copyStorageToClipboard ) ;
303+ chrome . runtime . onMessage . addListener ( addMessageListener ) ;
304+ chrome . runtime . onMessage . addListener ( deleteMessageListener ) ;
249305} ;
250306
251307main ( ) ;
0 commit comments